Skip to content

Commit

Permalink
Merge branch 'main' into multiarchimage
Browse files Browse the repository at this point in the history
  • Loading branch information
YashasviDevtron authored Jun 15, 2024
2 parents cd6f867 + 1c7b816 commit a1af900
Show file tree
Hide file tree
Showing 48 changed files with 6,480 additions and 75 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.20 AS build-env
FROM golang:1.21 AS build-env

RUN echo $GOPATH
RUN apt update
Expand Down
8 changes: 1 addition & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -187,14 +187,8 @@ Devtron is built on some of the most trusted and loved technologies:

## :muscle: Trusted By

Devtron is trusted by Enterprises and Communities all across the globe:
<br>
Devtron is trusted by communities all across the globe. The list of organizations using Devtron can be found [here](./USERS.MD).

- [Delhivery:](https://www.delhivery.com/) Delhivery is an Indian delivery and e-commerce logistics company, that provides end-to-end Supply Chain solutions through cutting-edge technology
- [BharatPe:](https://bharatpe.com/) Bharatpe is an Indian fintech company that offers a range of products including interoperable QR codes for UPI payments, POS machines for card acceptance, and small business financing
- [Livspace:](https://www.livspace.com/in) Livspace is a home interior and renovation company, that provides interior design and renovation services in Singapore and India
- [Moglix:](https://www.moglix.com/) Moglix is an industrial B2B marketplace and an e-commerce platform for industrial tools and equipment, used largely by businesses in India
- [Xoxoday:](https://www.xoxoday.com/) Xoxoday provides technology infrastructure to enable businesses to automate rewards, incentives & payouts for employees, customers & channel partners

## :question: FAQs & Troubleshooting

Expand Down
26 changes: 26 additions & 0 deletions USERS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Who is using Devtron?

As the community grows, we want to keep track of the users and organizations using Devtron. If you're using Devtron, please raise a PR to add your organization name and a link to your webpage.

Currently, Devtron is being used by the following organizations:

1. [73strings](https://www.73strings.com/)
2. [Ather Energy](https://www.atherenergy.com/)
3. [BharatPe](https://bharatpe.com/)
4. [Birdeye](https://birdeye.com/)
5. [Bluecopa](https://www.bluecopa.com/)
6. [Chitale Bandhu](https://www.chitalebandhu.in/)
7. [Centricity](https://centricity.co.in/)
8. [Cyble](https://cyble.com/)
9. [Delhivery](https://www.delhivery.com/)
10. [KHEL Group](https://thekhelgroup.com/)
11. [Lemnisk](https://www.lemnisk.co/)
12. [OTPLess](https://otpless.com/)
14. [Spinny](https://www.spinny.com/)
15. [Tata 1Mg](https://www.1mg.com/)
16. [TravClan](https://www.travclan.com/)
17. [Unity Small Finance Bank](https://theunitybank.com/)
18. [Xoxoday](https://www.xoxoday.com/)



2 changes: 1 addition & 1 deletion cmd/external-app/wire_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 11 additions & 8 deletions pkg/auth/user/UserCommonService.go
Original file line number Diff line number Diff line change
Expand Up @@ -572,13 +572,16 @@ func (impl UserCommonServiceImpl) CheckRbacForClusterEntity(cluster, namespace,
resourceObj = "*"
}

rbacResource := fmt.Sprintf("%s/%s/%s", strings.ToLower(cluster), strings.ToLower(namespaceObj), casbin.ResourceUser)
resourcesArray := strings.Split(resourceObj, ",")
for _, resourceVal := range resourcesArray {
rbacObject := fmt.Sprintf("%s/%s/%s", groupObj, kindObj, resourceVal)
allowed := managerAuth(rbacResource, token, rbacObject)
if !allowed {
return false
namespacesArray := strings.Split(namespaceObj, ",")
for _, namespaceInArray := range namespacesArray {
rbacResource := fmt.Sprintf("%s/%s/%s", strings.ToLower(cluster), strings.ToLower(namespaceInArray), casbin.ResourceUser)
for _, resourceVal := range resourcesArray {
rbacObject := fmt.Sprintf("%s/%s/%s", groupObj, kindObj, resourceVal)
allowed := managerAuth(rbacResource, token, rbacObject)
if !allowed {
return false
}
}
}
return true
Expand Down Expand Up @@ -690,8 +693,8 @@ func (impl UserCommonServiceImpl) GetUniqueKeyForAllEntity(role repository.RoleM
key = fmt.Sprintf("%s_%s_%s_%s", role.Team, role.Action, role.AccessType, role.Entity)
} else if len(role.Entity) > 0 {
if role.Entity == bean.CLUSTER_ENTITIY {
key = fmt.Sprintf("%s_%s_%s_%s_%s_%s", role.Entity, role.Action, role.Cluster,
role.Namespace, role.Group, role.Kind)
key = fmt.Sprintf("%s_%s_%s_%s_%s", role.Entity, role.Action, role.Cluster,
role.Group, role.Kind)
} else {
key = fmt.Sprintf("%s_%s", role.Entity, role.Action)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package chartRef

import (
"bytes"
"context"
"encoding/json"
"errors"
"fmt"
Expand All @@ -29,8 +30,10 @@ import (
util2 "github.com/devtron-labs/devtron/util"
dirCopy "github.com/otiai10/copy"
"go.uber.org/zap"
"golang.org/x/exp/maps"
"io/ioutil"
"k8s.io/helm/pkg/chartutil"
chart2 "k8s.io/helm/pkg/proto/hapi/chart"
"os"
"path"
"path/filepath"
Expand Down Expand Up @@ -70,19 +73,21 @@ type ChartRefFileOpService interface {
GetRefChart(chartRefId int) (string, string, string, string, error)
ExtractChartIfMissing(chartData []byte, refChartDir string, location string) (*bean.ChartDataInfo, error)
GetChartInBytes(chartRefId int, deleteChart bool) ([]byte, error)
GetChartBytesInBulk(chartRefIds []int, deleteChart bool) (map[int][]byte, error)
GetChartBytesForApps(ctx context.Context, appIdToAppName map[int]string) (map[int][]byte, error)
}

type ChartRefServiceImpl struct {
logger *zap.SugaredLogger
chartRefRepository chartRepoRepository.ChartRefRepository
chartTemplateService util.ChartTemplateService
mergeUtil util.MergeUtil
chartRepository chartRepoRepository.ChartRepository
}

func NewChartRefServiceImpl(logger *zap.SugaredLogger,
chartRefRepository chartRepoRepository.ChartRefRepository,
chartTemplateService util.ChartTemplateService,
chartRepository chartRepoRepository.ChartRepository,
mergeUtil util.MergeUtil) *ChartRefServiceImpl {
// cache devtron reference charts list
devtronChartList, _ := chartRefRepository.FetchAllNonUserUploadedChartInfo()
Expand All @@ -92,6 +97,7 @@ func NewChartRefServiceImpl(logger *zap.SugaredLogger,
chartRefRepository: chartRefRepository,
chartTemplateService: chartTemplateService,
mergeUtil: mergeUtil,
chartRepository: chartRepository,
}
}

Expand Down Expand Up @@ -309,23 +315,83 @@ func (impl *ChartRefServiceImpl) extractChartInBytes(chartRef *chartRepoReposito
}
return manifestByteArr, nil
}
func (impl *ChartRefServiceImpl) GetChartBytesInBulk(chartRefIds []int, performCleanup bool) (map[int][]byte, error) {

func (impl *ChartRefServiceImpl) getChartPath(chartRef *chartRepoRepository.ChartRef) (string, error) {
refChartPath := filepath.Join(bean.RefChartDirPath, chartRef.Location)
// For user uploaded charts ChartData will be retrieved from DB
if chartRef.ChartData != nil {
chartInfo, err := impl.ExtractChartIfMissing(chartRef.ChartData, bean.RefChartDirPath, chartRef.Location)
if chartInfo != nil && chartInfo.TemporaryFolder != "" {
err1 := os.RemoveAll(chartInfo.TemporaryFolder)
if err1 != nil {
impl.logger.Errorw("error in deleting temp dir ", "err", err)
}
}
} else {
// For Devtron reference charts the chart will be load from the directory location
}
return refChartPath, nil
}

func (impl *ChartRefServiceImpl) GetChartBytesForApps(ctx context.Context, appIdToAppName map[int]string) (map[int][]byte, error) {

appIds := maps.Keys(appIdToAppName)
charts, err := impl.chartRepository.FindLatestChartByAppIds(appIds)
if err != nil {
impl.logger.Errorw("error in fetching chart", "err", err, "appIds", appIds)
return nil, err
}

chartRefIdTOAppIds := make(map[int][]int)
var chartRefIds []int
chartRefToChartVersion := make(map[int]string)

for _, chart := range charts {
chartRefIds = append(chartRefIds, chart.ChartRefId)
chartRefToChartVersion[chart.ChartRefId] = chart.ChartVersion
refAppIds, ok := chartRefIdTOAppIds[chart.ChartRefId]
if !ok {
refAppIds = make([]int, 0)
}
refAppIds = append(refAppIds, chart.AppId)
chartRefIdTOAppIds[chart.ChartRefId] = refAppIds
}

chartRefs, err := impl.chartRefRepository.FindByIds(chartRefIds)
if err != nil {
impl.logger.Errorw("error getting chart data", "chartRefIds", chartRefIds, "err", err)
return nil, err
}
chartRefIdToBytes := make(map[int][]byte)

appIdToBytes := make(map[int][]byte)

// this loops run with O(len(apps)) T.C
for _, chartRef := range chartRefs {
chartInBytes, err := impl.extractChartInBytes(chartRef, performCleanup)
refChartPath, err := impl.getChartPath(chartRef)
if err != nil {
impl.logger.Errorw("error in converting chart to bytes", "chartRefId", chartRef.Id, "err", err)
return nil, err
}
chartRefIdToBytes[chartRef.Id] = chartInBytes

refAppIds := chartRefIdTOAppIds[chartRef.Id]
for _, appId := range refAppIds {
chartMetaData := &chart2.Metadata{
Name: appIdToAppName[appId],
Version: chartRefToChartVersion[chartRef.Id],
}
tempReferenceTemplateDir, err := impl.chartTemplateService.BuildChart(ctx, chartMetaData, refChartPath)
if err != nil {
impl.logger.Errorw("error in building chart", "chartMetaData", chartMetaData, "refChartPath", refChartPath)
return nil, err
}
chartInBytes, err := impl.chartTemplateService.LoadChartInBytes(tempReferenceTemplateDir, true)
appIdToBytes[appId] = chartInBytes
}

}
return chartRefIdToBytes, nil
return appIdToBytes, nil
}

func (impl *ChartRefServiceImpl) FetchCustomChartsInfo() ([]*bean.ChartDto, error) {
resultsMetadata, err := impl.chartRefRepository.GetAllChartMetadata()
if err != nil {
Expand Down
7 changes: 7 additions & 0 deletions pkg/generateManifest/DeploymentTemplateService.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import (
"github.com/gammazero/workerpool"
"github.com/go-pg/pg"
"go.uber.org/zap"
"golang.org/x/exp/maps"
"net/http"
"os"
"regexp"
Expand Down Expand Up @@ -422,6 +423,12 @@ func (impl DeploymentTemplateServiceImpl) GetRestartWorkloadData(ctx context.Con
var finalError error
for i, _ := range partitionedRequests {
req := partitionedRequests[i]
err = impl.setChartContent(ctx, req, appNameToId)
if err != nil {
impl.Logger.Errorw("error in setting chart content for apps", "appNames", maps.Keys(appNameToId), "err", err)
// continue processing next batch
continue
}
wp.Submit(func() {
resp, err := impl.helmAppClient.TemplateChartBulk(ctx, &gRPC.BulkInstallReleaseRequest{BulkInstallReleaseRequest: req})
if err != nil {
Expand Down
67 changes: 29 additions & 38 deletions pkg/generateManifest/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,15 @@
package generateManifest

import (
"context"
"fmt"
"github.com/devtron-labs/common-lib/utils/yaml"
"github.com/devtron-labs/devtron/api/helm-app/bean"
"github.com/devtron-labs/devtron/api/helm-app/gRPC"
"github.com/devtron-labs/devtron/internal/sql/repository/app"
"github.com/devtron-labs/devtron/pkg/cluster/repository"
"go.opentelemetry.io/otel"
"golang.org/x/exp/maps"
)

func (impl DeploymentTemplateServiceImpl) constructRotatePodResponse(templateChartResponse []*gRPC.TemplateChartResponse, appNameToId map[string]int, environment *repository.Environment) (*RestartPodResponse, error) {
Expand All @@ -37,23 +40,15 @@ func (impl DeploymentTemplateServiceImpl) constructRotatePodResponse(templateCha
for _, manifest := range manifests {
gvk := manifest.GroupVersionKind()
name := manifest.GetName()
labels := manifest.GetLabels()
switch gvk.Kind {
case string(Deployment), string(StatefulSet), string(DemonSet), string(Rollout):
if labels != nil && labels[LabelReleaseKey] != "" {
resourceMeta = append(resourceMeta, &ResourceMetadata{
Name: labels[LabelReleaseKey],
GroupVersionKind: gvk,
})
} else {
resourceMeta = append(resourceMeta, &ResourceMetadata{
Name: name,
GroupVersionKind: gvk,
})
}

resourceMeta = append(resourceMeta, &ResourceMetadata{
Name: name,
GroupVersionKind: gvk,
})
}
}

appIdToResourceIdentifier[appNameToId[tcResp.AppName]] = &ResourceIdentifierResponse{
ResourceMetaData: resourceMeta,
AppName: appName,
Expand Down Expand Up @@ -91,10 +86,12 @@ func (impl DeploymentTemplateServiceImpl) constructInstallReleaseBulkReq(apps []
if appIdToInstallReleaseRequest == nil || len(appIdToInstallReleaseRequest) == 0 {
return nil, err
}
err = impl.setChartContent(applicationIds, appIdToInstallReleaseRequest)
if err != nil {
impl.Logger.Errorw("error in setting chart content", "appIds", applicationIds, "err", err)
return nil, err

for _, app := range apps {
if _, ok := appIdToInstallReleaseRequest[app.Id]; ok {
appIdToInstallReleaseRequest[app.Id].AppName = app.AppName
appIdToInstallReleaseRequest[app.Id].ChartRepository = ChartRepository
}
}

k8sServerVersion, err := impl.K8sUtil.GetKubeVersion()
Expand All @@ -111,8 +108,6 @@ func (impl DeploymentTemplateServiceImpl) constructInstallReleaseBulkReq(apps []
if _, ok := appIdToInstallReleaseRequest[app.Id]; ok {
appIdToInstallReleaseRequest[app.Id].ReleaseIdentifier = impl.getReleaseIdentifier(config, app, environment)
appIdToInstallReleaseRequest[app.Id].K8SVersion = k8sServerVersion.String()
appIdToInstallReleaseRequest[app.Id].AppName = app.AppName
appIdToInstallReleaseRequest[app.Id].ChartRepository = ChartRepository
}
}

Expand All @@ -122,30 +117,26 @@ func (impl DeploymentTemplateServiceImpl) constructInstallReleaseBulkReq(apps []
return installReleaseRequests, nil
}

func (impl DeploymentTemplateServiceImpl) setChartContent(appIds []int, appIdToInstallReleaseRequest map[int]*gRPC.InstallReleaseRequest) error {
charts, err := impl.chartRepository.FindLatestChartByAppIds(appIds)
if err != nil {
impl.Logger.Errorw("error in fetching chart", "err", err, "appIds", appIds)
return err
}
appIdToChartRefId := make(map[int]int)
var chartRefIds []int
for _, chart := range charts {
appIdToChartRefId[chart.AppId] = chart.ChartRefId
chartRefIds = append(chartRefIds, chart.ChartRefId)
func (impl DeploymentTemplateServiceImpl) setChartContent(ctx context.Context, installReleaseRequests []*gRPC.InstallReleaseRequest, appNameToId map[string]int) error {
appIdToInstallReleaseRequest := make(map[int]*gRPC.InstallReleaseRequest)
requestAppNameToId := make(map[int]string)
for _, req := range installReleaseRequests {
appId := appNameToId[req.AppName]
requestAppNameToId[appId] = req.AppName
appIdToInstallReleaseRequest[appId] = req
}
chartRefIdToBytes, err := impl.chartRefService.GetChartBytesInBulk(chartRefIds, false)

_, span := otel.Tracer("orchestrator").Start(ctx, "chartRefService.GetChartBytesForApps")
appIdToBytes, err := impl.chartRefService.GetChartBytesForApps(ctx, requestAppNameToId)
span.End()
if err != nil {
impl.Logger.Errorw("error in fetching chartRefBean", "err", err, "chartRefIds", chartRefIds)
impl.Logger.Errorw("error in fetching chartRefBean", "err", err, "appNames", maps.Keys(appNameToId))
return err
}
for appId, chartRefId := range appIdToChartRefId {
if bytes, ok := chartRefIdToBytes[chartRefId]; ok {
if _, ok := appIdToInstallReleaseRequest[appId]; ok {
appIdToInstallReleaseRequest[appId].ChartContent = &gRPC.ChartContent{Content: bytes}
}
}
for appId, _ := range appIdToInstallReleaseRequest {
appIdToInstallReleaseRequest[appId].ChartContent = &gRPC.ChartContent{Content: appIdToBytes[appId]}
}

return err
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ metadata:
chart: {{ template ".Chart.Name .chart" . }}
release: {{ .Release.Name }}
{{- if .Values.appLabels }}
{{ toYaml .Values.appLabels | indent 4 }}
{{ toYaml .Values.appLabels | indent 4 }}
{{- end }}
{{- if .Values.kedaAutoscaling.labels }}
{{ toYaml .Values.kedaAutoscaling.labels | indent 4 }}
{{ toYaml .Values.kedaAutoscaling.labels | indent 4 }}
{{- end }}
{{- if .Values.kedaAutoscaling.annotations }}
annotations:
{{ toYaml .Values.kedaAutoscaling.annotations | indent 4 }}
{{ toYaml .Values.kedaAutoscaling.annotations | indent 4 }}
{{- end }}
spec:
scaleTargetRef:
Expand Down
Loading

0 comments on commit a1af900

Please sign in to comment.