Skip to content

Commit 364f7ca

Browse files
committed
Merge branch 'main' into manifest-template-fix
2 parents 858b9f5 + 4f7db1c commit 364f7ca

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+18125
-59
lines changed

api/helm-app/gRPC/applicationClient.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"context"
2121
"fmt"
2222
"github.com/caarlos0/env"
23+
grpcUtil "github.com/devtron-labs/common-lib/utils/grpc"
2324
"go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc"
2425
"go.opentelemetry.io/otel"
2526
"go.uber.org/zap"
@@ -55,12 +56,16 @@ type HelmAppClientImpl struct {
5556
logger *zap.SugaredLogger
5657
helmClientConfig *HelmClientConfig
5758
applicationServiceClient ApplicationServiceClient
59+
grpcConfig *grpcUtil.Configuration
5860
}
5961

60-
func NewHelmAppClientImpl(logger *zap.SugaredLogger, helmClientConfig *HelmClientConfig) *HelmAppClientImpl {
62+
func NewHelmAppClientImpl(logger *zap.SugaredLogger,
63+
helmClientConfig *HelmClientConfig,
64+
grpcConfig *grpcUtil.Configuration) *HelmAppClientImpl {
6165
return &HelmAppClientImpl{
6266
logger: logger,
6367
helmClientConfig: helmClientConfig,
68+
grpcConfig: grpcConfig,
6469
}
6570
}
6671

@@ -94,7 +99,8 @@ func (impl *HelmAppClientImpl) getConnection() (*grpc.ClientConn, error) {
9499
grpc.WithBlock(),
95100
grpc.WithInsecure(),
96101
grpc.WithDefaultCallOptions(
97-
grpc.MaxCallRecvMsgSize(20*1024*1024),
102+
grpc.MaxCallRecvMsgSize(impl.grpcConfig.KubelinkMaxSendMsgSize*1024*1024), // GRPC Request size
103+
grpc.MaxCallSendMsgSize(impl.grpcConfig.KubelinkMaxRecvMsgSize*1024*1024), // GRPC Response size
98104
),
99105
grpc.WithDefaultServiceConfig(`{"loadBalancingPolicy":"round_robin"}`),
100106
)

api/helm-app/wire_helmApp.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,15 @@
1717
package client
1818

1919
import (
20+
grpcUtil "github.com/devtron-labs/common-lib/utils/grpc"
2021
"github.com/devtron-labs/devtron/api/helm-app/gRPC"
2122
"github.com/devtron-labs/devtron/api/helm-app/service"
2223
"github.com/devtron-labs/devtron/util/rbac"
2324
"github.com/google/wire"
2425
)
2526

2627
var HelmAppWireSet = wire.NewSet(
28+
grpcUtil.GetConfiguration,
2729
gRPC.NewHelmAppClientImpl,
2830
wire.Bind(new(gRPC.HelmAppClient), new(*gRPC.HelmAppClientImpl)),
2931
service.GetHelmReleaseConfig,

api/k8s/application/k8sApplicationRestHandler.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -970,7 +970,9 @@ func (handler *K8sApplicationRestHandlerImpl) GetResourceList(w http.ResponseWri
970970
}
971971
clusterRbacFunc := handler.verifyRbacForCluster
972972
if isSuperAdmin {
973-
clusterRbacFunc = nil
973+
clusterRbacFunc = func(token, clusterName string, request k8s.ResourceRequestBean, casbinAction string) bool {
974+
return true
975+
}
974976
}
975977
response, err := handler.k8sApplicationService.GetResourceList(r.Context(), token, &request, clusterRbacFunc)
976978
if err != nil {

cmd/external-app/wire_gen.go

Lines changed: 6 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

env_gen.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,8 @@
171171
| K8s_TCP_KEEPALIVE | 30 | |
172172
| K8s_TCP_TIMEOUT | 30 | |
173173
| K8s_TLS_HANDSHAKE_TIMEOUT | 10 | |
174+
| KUBELINK_GRPC_MAX_RECEIVE_MSG_SIZE | 20 | |
175+
| KUBELINK_GRPC_MAX_SEND_MSG_SIZE | 4 | |
174176
| LENS_TIMEOUT | 0 | |
175177
| LENS_URL | http://lens-milandevtron-service:80 | |
176178
| LIMIT_CI_CPU | 0.5 | |
@@ -208,6 +210,7 @@
208210
| PRE_CI_CACHE_PATH | /devtroncd-cache | |
209211
| PROPAGATE_EXTRA_LABELS | false | |
210212
| PROXY_SERVICE_CONFIG | {} | |
213+
| REPLICAS | 0 | |
211214
| REQ_CI_CPU | 0.5 | |
212215
| REQ_CI_MEM | 3G | |
213216
| RESOURCE_LIST_FOR_REPLICAS | Deployment,Rollout,StatefulSet,ReplicaSet | |

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ require (
8383
gopkg.in/go-playground/validator.v9 v9.30.0
8484
gopkg.in/igm/sockjs-go.v3 v3.0.0
8585
gopkg.in/yaml.v2 v2.4.0
86+
helm.sh/helm/v3 v3.14.3
8687
k8s.io/api v0.29.0
8788
k8s.io/apimachinery v0.29.0
8889
k8s.io/client-go v0.29.0

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1235,6 +1235,8 @@ gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776/go.mod h1:K4uyk7z7BCEPqu6E+C
12351235
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
12361236
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
12371237
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
1238+
helm.sh/helm/v3 v3.14.3 h1:HmvRJlwyyt9HjgmAuxHbHv3PhMz9ir/XNWHyXfmnOP4=
1239+
helm.sh/helm/v3 v3.14.3/go.mod h1:v6myVbyseSBJTzhmeE39UcPLNv6cQK6qss3dvgAySaE=
12381240
honnef.co/go/tools v0.0.0-20180728063816-88497007e858/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
12391241
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
12401242
honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=

internal/util/ChartTemplateService.go

Lines changed: 51 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,23 @@ package util
1919
import (
2020
"compress/gzip"
2121
"context"
22+
"encoding/json"
2223
"fmt"
24+
dockerRegistryRepository "github.com/devtron-labs/devtron/internal/sql/repository/dockerRegistry"
25+
dirCopy "github.com/otiai10/copy"
26+
"go.opentelemetry.io/otel"
27+
"go.uber.org/zap"
28+
"helm.sh/helm/v3/pkg/chart"
29+
"helm.sh/helm/v3/pkg/chart/loader"
30+
"helm.sh/helm/v3/pkg/chartutil"
2331
"io/ioutil"
2432
"math/rand"
2533
"os"
2634
"path/filepath"
35+
"sigs.k8s.io/yaml"
2736
"strconv"
2837
"strings"
2938
"time"
30-
31-
dockerRegistryRepository "github.com/devtron-labs/devtron/internal/sql/repository/dockerRegistry"
32-
dirCopy "github.com/otiai10/copy"
33-
"go.opentelemetry.io/otel"
34-
"go.uber.org/zap"
35-
"k8s.io/helm/pkg/chartutil"
36-
"k8s.io/helm/pkg/proto/hapi/chart"
37-
"sigs.k8s.io/yaml"
3839
)
3940

4041
const (
@@ -101,13 +102,7 @@ func (impl ChartTemplateServiceImpl) GetChartVersion(location string) (string, e
101102
if _, err := os.Stat(chartYaml); os.IsNotExist(err) {
102103
return "", fmt.Errorf("Chart.yaml file not present in the directory %q", location)
103104
}
104-
//chartYaml = filepath.Join(chartYaml,filepath.Clean(chartYaml))
105-
chartYamlContent, err := ioutil.ReadFile(filepath.Clean(chartYaml))
106-
if err != nil {
107-
return "", fmt.Errorf("cannot read Chart.Yaml in directory %q", location)
108-
}
109-
110-
chartContent, err := chartutil.UnmarshalChartfile(chartYamlContent)
105+
chartContent, err := chartutil.LoadChartfile(filepath.Clean(chartYaml))
111106
if err != nil {
112107
return "", fmt.Errorf("cannot read Chart.Yaml in directory %q", location)
113108
}
@@ -116,7 +111,7 @@ func (impl ChartTemplateServiceImpl) GetChartVersion(location string) (string, e
116111
}
117112

118113
func (impl ChartTemplateServiceImpl) FetchValuesFromReferenceChart(chartMetaData *chart.Metadata, refChartLocation string, templateName string, userId int32, pipelineStrategyPath string) (*ChartValues, error) {
119-
chartMetaData.ApiVersion = "v1" // ensure always v1
114+
chartMetaData.APIVersion = "v1" // ensure always v1
120115
dir := impl.GetDir()
121116
chartDir := filepath.Join(CHART_WORKING_DIR_PATH, dir)
122117
impl.logger.Debugw("chart dir ", "chart", chartMetaData.Name, "dir", chartDir)
@@ -155,7 +150,9 @@ func (impl ChartTemplateServiceImpl) FetchValuesFromReferenceChart(chartMetaData
155150

156151
// TODO: convert BuildChart and BuildChartProxyForHelmApps into one function
157152
func (impl ChartTemplateServiceImpl) BuildChart(ctx context.Context, chartMetaData *chart.Metadata, referenceTemplatePath string) (string, error) {
158-
chartMetaData.ApiVersion = "v1" // ensure always v1
153+
if chartMetaData.APIVersion == "" {
154+
chartMetaData.APIVersion = "v1" // ensure always v1
155+
}
159156
dir := impl.GetDir()
160157
tempReferenceTemplateDir := filepath.Join(CHART_WORKING_DIR_PATH, dir)
161158
impl.logger.Debugw("chart dir ", "chart", chartMetaData.Name, "dir", tempReferenceTemplateDir)
@@ -183,7 +180,7 @@ func (impl ChartTemplateServiceImpl) BuildChart(ctx context.Context, chartMetaDa
183180
func (impl ChartTemplateServiceImpl) BuildChartProxyForHelmApps(chartCreateRequest *ChartCreateRequest) (*ChartCreateResponse, error) {
184181
chartCreateResponse := &ChartCreateResponse{}
185182
chartMetaData := chartCreateRequest.ChartMetaData
186-
chartMetaData.ApiVersion = "v2" // ensure always v2
183+
chartMetaData.APIVersion = "v2" // ensure always v2
187184
dir := impl.GetDir()
188185
chartDir := filepath.Join(CHART_WORKING_DIR_PATH, dir)
189186
impl.logger.Debugw("chart dir ", "chart", chartMetaData.Name, "dir", chartDir)
@@ -282,42 +279,60 @@ func (impl ChartTemplateServiceImpl) getValues(directory, pipelineStrategyPath s
282279

283280
}
284281

285-
func (impl ChartTemplateServiceImpl) PackageChart(tempReferenceTemplateDir string, chartMetaData *chart.Metadata) (*string, string, error) {
286-
valid, err := chartutil.IsChartDir(tempReferenceTemplateDir)
282+
func (impl ChartTemplateServiceImpl) overrideChartMetaDataInDir(chartDir string, chartMetaData *chart.Metadata) (*chart.Chart, error) {
283+
chart, err := loader.LoadDir(chartDir)
287284
if err != nil {
288-
impl.logger.Errorw("error in validating base chart", "dir", tempReferenceTemplateDir, "err", err)
289-
return nil, "", err
285+
impl.logger.Errorw("error in loading template chart", "chartPath", chartDir, "err", err)
286+
return nil, err
290287
}
291-
if !valid {
292-
impl.logger.Errorw("invalid chart at ", "dir", tempReferenceTemplateDir)
293-
return nil, "", fmt.Errorf("invalid base chart")
288+
if len(chartMetaData.Name) > 0 {
289+
chart.Metadata.Name = chartMetaData.Name
294290
}
295-
296-
b, err := yaml.Marshal(chartMetaData)
291+
if len(chartMetaData.Version) > 0 {
292+
chart.Metadata.Version = chartMetaData.Version
293+
}
294+
chartMetaDataBytes, err := yaml.Marshal(chart.Metadata)
297295
if err != nil {
298296
impl.logger.Errorw("error in marshaling chartMetadata", "err", err)
299-
return nil, "", err
297+
return chart, err
300298
}
301-
err = ioutil.WriteFile(filepath.Join(tempReferenceTemplateDir, "Chart.yaml"), b, 0600)
299+
err = ioutil.WriteFile(filepath.Join(chartDir, "Chart.yaml"), chartMetaDataBytes, 0600)
302300
if err != nil {
303301
impl.logger.Errorw("err in writing Chart.yaml", "err", err)
302+
return chart, err
303+
}
304+
return chart, nil
305+
}
306+
307+
func (impl ChartTemplateServiceImpl) PackageChart(tempReferenceTemplateDir string, chartMetaData *chart.Metadata) (*string, string, error) {
308+
valid, err := chartutil.IsChartDir(tempReferenceTemplateDir)
309+
if err != nil {
310+
impl.logger.Errorw("error in validating base chart", "dir", tempReferenceTemplateDir, "err", err)
304311
return nil, "", err
305312
}
306-
chart, err := chartutil.LoadDir(tempReferenceTemplateDir)
313+
if !valid {
314+
impl.logger.Errorw("invalid chart at ", "dir", tempReferenceTemplateDir)
315+
return nil, "", fmt.Errorf("invalid base chart")
316+
}
317+
chart, err := impl.overrideChartMetaDataInDir(tempReferenceTemplateDir, chartMetaData)
307318
if err != nil {
308-
impl.logger.Errorw("error in loading chart dir", "err", err, "dir", tempReferenceTemplateDir)
319+
impl.logger.Errorw("error in overriding chart metadata", "chartPath", tempReferenceTemplateDir, "err", err)
309320
return nil, "", err
310321
}
311-
312322
archivePath, err := chartutil.Save(chart, tempReferenceTemplateDir)
313323
if err != nil {
314324
impl.logger.Errorw("error in saving", "err", err, "dir", tempReferenceTemplateDir)
315325
return nil, "", err
316326
}
317327
impl.logger.Debugw("chart archive path", "path", archivePath)
318328
var valuesYaml string
329+
byteValues, err := json.Marshal(chart.Values)
330+
if err != nil {
331+
impl.logger.Errorw("error in json Marshal values", "values", chart.Values, "err", err)
332+
return nil, "", err
333+
}
319334
if chart.Values != nil {
320-
valuesYaml = chart.Values.Raw
335+
valuesYaml = string(byteValues)
321336
} else {
322337
impl.logger.Warnw("values.yaml not found in helm chart", "dir", tempReferenceTemplateDir)
323338
}
@@ -339,7 +354,7 @@ func (impl ChartTemplateServiceImpl) GetDir() string {
339354

340355
// GetByteArrayRefChart this method will be used for getting byte array from reference chart to store in db
341356
func (impl ChartTemplateServiceImpl) GetByteArrayRefChart(chartMetaData *chart.Metadata, referenceTemplatePath string) ([]byte, error) {
342-
chartMetaData.ApiVersion = "v1" // ensure always v1
357+
chartMetaData.APIVersion = "v1" // ensure always v1
343358
dir := impl.GetDir()
344359
tempReferenceTemplateDir := filepath.Join(CHART_WORKING_DIR_PATH, dir)
345360
impl.logger.Debugw("chart dir ", "chart", chartMetaData.Name, "dir", tempReferenceTemplateDir)
@@ -377,8 +392,7 @@ func (impl ChartTemplateServiceImpl) GetByteArrayRefChart(chartMetaData *chart.M
377392
func (impl ChartTemplateServiceImpl) LoadChartInBytes(ChartPath string, deleteChart bool) ([]byte, error) {
378393

379394
var chartBytesArr []byte
380-
//this function is removed in latest helm release and is replaced by Loader in loader package
381-
chart, err := chartutil.LoadDir(ChartPath)
395+
chart, err := loader.LoadDir(ChartPath)
382396
if err != nil {
383397
impl.logger.Errorw("error in loading chart dir", "err", err, "dir")
384398
return chartBytesArr, err
@@ -398,7 +412,7 @@ func (impl ChartTemplateServiceImpl) LoadChartInBytes(ChartPath string, deleteCh
398412

399413
func (impl ChartTemplateServiceImpl) LoadChartFromDir(dir string) (*chart.Chart, error) {
400414
//this function is removed in latest helm release and is replaced by Loader in loader package
401-
chart, err := chartutil.LoadDir(dir)
415+
chart, err := loader.LoadDir(dir)
402416
if err != nil {
403417
impl.logger.Errorw("error in loading chart dir", "err", err, "dir")
404418
return chart, err

internal/util/ChartTemplateService_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ package util
1919
import (
2020
"context"
2121
"github.com/stretchr/testify/assert"
22-
"k8s.io/helm/pkg/chartutil"
23-
chart2 "k8s.io/helm/pkg/proto/hapi/chart"
22+
"helm.sh/helm/v3/pkg/chart"
23+
"helm.sh/helm/v3/pkg/chartutil"
2424
"math/rand"
2525
"testing"
2626
)
@@ -47,7 +47,7 @@ func TestChartTemplateService(t *testing.T) {
4747
logger: logger,
4848
randSource: rand.NewSource(0),
4949
}
50-
chartMetaData := &chart2.Metadata{
50+
chartMetaData := &chart.Metadata{
5151
Name: "sample-app",
5252
Version: "1.0.0",
5353
}
@@ -69,7 +69,7 @@ func TestChartTemplateService(t *testing.T) {
6969
logger: logger,
7070
randSource: rand.NewSource(0),
7171
}
72-
chartMetaData := &chart2.Metadata{
72+
chartMetaData := &chart.Metadata{
7373
Name: "sample-app",
7474
Version: "1.0.0",
7575
}
@@ -92,7 +92,7 @@ func TestChartTemplateService(t *testing.T) {
9292
logger: logger,
9393
randSource: rand.NewSource(0),
9494
}
95-
chartMetaData := &chart2.Metadata{
95+
chartMetaData := &chart.Metadata{
9696
Name: "sample-app",
9797
Version: "1.0.0",
9898
}

internal/util/mocks/ChartTemplateService.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/appStore/installedApp/adapter/Adapter.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import (
2020
"github.com/devtron-labs/devtron/internal/util"
2121
appStoreBean "github.com/devtron-labs/devtron/pkg/appStore/bean"
2222
"github.com/devtron-labs/devtron/pkg/deployment/gitOps/git/bean"
23-
"k8s.io/helm/pkg/proto/hapi/chart"
23+
"helm.sh/helm/v3/pkg/chart"
2424
"path"
2525
)
2626

pkg/appStore/installedApp/service/common/AppStoreDeploymentCommonService.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import (
2222
appStoreBean "github.com/devtron-labs/devtron/pkg/appStore/bean"
2323
appStoreDiscoverRepository "github.com/devtron-labs/devtron/pkg/appStore/discover/repository"
2424
"go.uber.org/zap"
25-
"k8s.io/helm/pkg/chartutil"
25+
"helm.sh/helm/v3/pkg/chartutil"
2626
"sigs.k8s.io/yaml"
2727
)
2828

pkg/chart/ChartService.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ import (
4141
"github.com/juju/errors"
4242
"go.opentelemetry.io/otel"
4343
"go.uber.org/zap"
44-
"k8s.io/helm/pkg/proto/hapi/chart"
44+
"helm.sh/helm/v3/pkg/chart"
4545
"path/filepath"
4646
"sigs.k8s.io/yaml"
4747
"strconv"

pkg/deployment/manifest/deploymentTemplate/DeploymentTemplateService.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import (
2626
bean4 "github.com/devtron-labs/devtron/pkg/deployment/manifest/deploymentTemplate/chartRef/bean"
2727
"go.opentelemetry.io/otel"
2828
"go.uber.org/zap"
29-
chart2 "k8s.io/helm/pkg/proto/hapi/chart"
29+
"helm.sh/helm/v3/pkg/chart"
3030
"os"
3131
"path"
3232
"path/filepath"
@@ -66,7 +66,7 @@ func (impl *DeploymentTemplateServiceImpl) BuildChartAndGetPath(appName string,
6666
return "", err
6767
}
6868
}
69-
chartMetaData := &chart2.Metadata{
69+
chartMetaData := &chart.Metadata{
7070
Name: appName,
7171
Version: envOverride.Chart.ChartVersion,
7272
}

0 commit comments

Comments
 (0)