Skip to content

feat: updated kubelink grpc client cfg #5426

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Jul 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions api/helm-app/gRPC/applicationClient.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"context"
"fmt"
"github.com/caarlos0/env"
grpcUtil "github.com/devtron-labs/common-lib/utils/grpc"
"go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc"
"go.opentelemetry.io/otel"
"go.uber.org/zap"
Expand Down Expand Up @@ -55,12 +56,16 @@ type HelmAppClientImpl struct {
logger *zap.SugaredLogger
helmClientConfig *HelmClientConfig
applicationServiceClient ApplicationServiceClient
grpcConfig *grpcUtil.Configuration
}

func NewHelmAppClientImpl(logger *zap.SugaredLogger, helmClientConfig *HelmClientConfig) *HelmAppClientImpl {
func NewHelmAppClientImpl(logger *zap.SugaredLogger,
helmClientConfig *HelmClientConfig,
grpcConfig *grpcUtil.Configuration) *HelmAppClientImpl {
return &HelmAppClientImpl{
logger: logger,
helmClientConfig: helmClientConfig,
grpcConfig: grpcConfig,
}
}

Expand Down Expand Up @@ -94,7 +99,8 @@ func (impl *HelmAppClientImpl) getConnection() (*grpc.ClientConn, error) {
grpc.WithBlock(),
grpc.WithInsecure(),
grpc.WithDefaultCallOptions(
grpc.MaxCallRecvMsgSize(20*1024*1024),
grpc.MaxCallRecvMsgSize(impl.grpcConfig.KubelinkMaxSendMsgSize*1024*1024), // GRPC Request size
grpc.MaxCallSendMsgSize(impl.grpcConfig.KubelinkMaxRecvMsgSize*1024*1024), // GRPC Response size
),
grpc.WithDefaultServiceConfig(`{"loadBalancingPolicy":"round_robin"}`),
)
Expand Down
2 changes: 2 additions & 0 deletions api/helm-app/wire_helmApp.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@
package client

import (
grpcUtil "github.com/devtron-labs/common-lib/utils/grpc"
"github.com/devtron-labs/devtron/api/helm-app/gRPC"
"github.com/devtron-labs/devtron/api/helm-app/service"
"github.com/devtron-labs/devtron/util/rbac"
"github.com/google/wire"
)

var HelmAppWireSet = wire.NewSet(
grpcUtil.GetConfiguration,
gRPC.NewHelmAppClientImpl,
wire.Bind(new(gRPC.HelmAppClient), new(*gRPC.HelmAppClientImpl)),
service.GetHelmReleaseConfig,
Expand Down
7 changes: 6 additions & 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.

2 changes: 2 additions & 0 deletions env_gen.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,8 @@
| K8s_TCP_KEEPALIVE | 30 | |
| K8s_TCP_TIMEOUT | 30 | |
| K8s_TLS_HANDSHAKE_TIMEOUT | 10 | |
| KUBELINK_GRPC_MAX_RECEIVE_MSG_SIZE | 20 | |
| KUBELINK_GRPC_MAX_SEND_MSG_SIZE | 4 | |
| LENS_TIMEOUT | 0 | |
| LENS_URL | http://lens-milandevtron-service:80 | |
| LIMIT_CI_CPU | 0.5 | |
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ require (
gopkg.in/go-playground/validator.v9 v9.30.0
gopkg.in/igm/sockjs-go.v3 v3.0.0
gopkg.in/yaml.v2 v2.4.0
helm.sh/helm/v3 v3.14.3
k8s.io/api v0.29.0
k8s.io/apimachinery v0.29.0
k8s.io/client-go v0.29.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1235,6 +1235,8 @@ gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776/go.mod h1:K4uyk7z7BCEPqu6E+C
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
helm.sh/helm/v3 v3.14.3 h1:HmvRJlwyyt9HjgmAuxHbHv3PhMz9ir/XNWHyXfmnOP4=
helm.sh/helm/v3 v3.14.3/go.mod h1:v6myVbyseSBJTzhmeE39UcPLNv6cQK6qss3dvgAySaE=
honnef.co/go/tools v0.0.0-20180728063816-88497007e858/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
Expand Down
88 changes: 51 additions & 37 deletions internal/util/ChartTemplateService.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,23 @@ package util
import (
"compress/gzip"
"context"
"encoding/json"
"fmt"
dockerRegistryRepository "github.com/devtron-labs/devtron/internal/sql/repository/dockerRegistry"
dirCopy "github.com/otiai10/copy"
"go.opentelemetry.io/otel"
"go.uber.org/zap"
"helm.sh/helm/v3/pkg/chart"
"helm.sh/helm/v3/pkg/chart/loader"
"helm.sh/helm/v3/pkg/chartutil"
"io/ioutil"
"math/rand"
"os"
"path/filepath"
"sigs.k8s.io/yaml"
"strconv"
"strings"
"time"

dockerRegistryRepository "github.com/devtron-labs/devtron/internal/sql/repository/dockerRegistry"
dirCopy "github.com/otiai10/copy"
"go.opentelemetry.io/otel"
"go.uber.org/zap"
"k8s.io/helm/pkg/chartutil"
"k8s.io/helm/pkg/proto/hapi/chart"
"sigs.k8s.io/yaml"
)

const (
Expand Down Expand Up @@ -101,13 +102,7 @@ func (impl ChartTemplateServiceImpl) GetChartVersion(location string) (string, e
if _, err := os.Stat(chartYaml); os.IsNotExist(err) {
return "", fmt.Errorf("Chart.yaml file not present in the directory %q", location)
}
//chartYaml = filepath.Join(chartYaml,filepath.Clean(chartYaml))
chartYamlContent, err := ioutil.ReadFile(filepath.Clean(chartYaml))
if err != nil {
return "", fmt.Errorf("cannot read Chart.Yaml in directory %q", location)
}

chartContent, err := chartutil.UnmarshalChartfile(chartYamlContent)
chartContent, err := chartutil.LoadChartfile(filepath.Clean(chartYaml))
if err != nil {
return "", fmt.Errorf("cannot read Chart.Yaml in directory %q", location)
}
Expand All @@ -116,7 +111,7 @@ func (impl ChartTemplateServiceImpl) GetChartVersion(location string) (string, e
}

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

// TODO: convert BuildChart and BuildChartProxyForHelmApps into one function
func (impl ChartTemplateServiceImpl) BuildChart(ctx context.Context, chartMetaData *chart.Metadata, referenceTemplatePath string) (string, error) {
chartMetaData.ApiVersion = "v1" // ensure always v1
if chartMetaData.APIVersion == "" {
chartMetaData.APIVersion = "v1" // ensure always v1
}
dir := impl.GetDir()
tempReferenceTemplateDir := filepath.Join(CHART_WORKING_DIR_PATH, dir)
impl.logger.Debugw("chart dir ", "chart", chartMetaData.Name, "dir", tempReferenceTemplateDir)
Expand Down Expand Up @@ -183,7 +180,7 @@ func (impl ChartTemplateServiceImpl) BuildChart(ctx context.Context, chartMetaDa
func (impl ChartTemplateServiceImpl) BuildChartProxyForHelmApps(chartCreateRequest *ChartCreateRequest) (*ChartCreateResponse, error) {
chartCreateResponse := &ChartCreateResponse{}
chartMetaData := chartCreateRequest.ChartMetaData
chartMetaData.ApiVersion = "v2" // ensure always v2
chartMetaData.APIVersion = "v2" // ensure always v2
dir := impl.GetDir()
chartDir := filepath.Join(CHART_WORKING_DIR_PATH, dir)
impl.logger.Debugw("chart dir ", "chart", chartMetaData.Name, "dir", chartDir)
Expand Down Expand Up @@ -282,42 +279,60 @@ func (impl ChartTemplateServiceImpl) getValues(directory, pipelineStrategyPath s

}

func (impl ChartTemplateServiceImpl) PackageChart(tempReferenceTemplateDir string, chartMetaData *chart.Metadata) (*string, string, error) {
valid, err := chartutil.IsChartDir(tempReferenceTemplateDir)
func (impl ChartTemplateServiceImpl) overrideChartMetaDataInDir(chartDir string, chartMetaData *chart.Metadata) (*chart.Chart, error) {
chart, err := loader.LoadDir(chartDir)
if err != nil {
impl.logger.Errorw("error in validating base chart", "dir", tempReferenceTemplateDir, "err", err)
return nil, "", err
impl.logger.Errorw("error in loading template chart", "chartPath", chartDir, "err", err)
return nil, err
}
if !valid {
impl.logger.Errorw("invalid chart at ", "dir", tempReferenceTemplateDir)
return nil, "", fmt.Errorf("invalid base chart")
if len(chartMetaData.Name) > 0 {
chart.Metadata.Name = chartMetaData.Name
}

b, err := yaml.Marshal(chartMetaData)
if len(chartMetaData.Version) > 0 {
chart.Metadata.Version = chartMetaData.Version
}
chartMetaDataBytes, err := yaml.Marshal(chart.Metadata)
if err != nil {
impl.logger.Errorw("error in marshaling chartMetadata", "err", err)
return nil, "", err
return chart, err
}
err = ioutil.WriteFile(filepath.Join(tempReferenceTemplateDir, "Chart.yaml"), b, 0600)
err = ioutil.WriteFile(filepath.Join(chartDir, "Chart.yaml"), chartMetaDataBytes, 0600)
if err != nil {
impl.logger.Errorw("err in writing Chart.yaml", "err", err)
return chart, err
}
return chart, nil
}

func (impl ChartTemplateServiceImpl) PackageChart(tempReferenceTemplateDir string, chartMetaData *chart.Metadata) (*string, string, error) {
valid, err := chartutil.IsChartDir(tempReferenceTemplateDir)
if err != nil {
impl.logger.Errorw("error in validating base chart", "dir", tempReferenceTemplateDir, "err", err)
return nil, "", err
}
chart, err := chartutil.LoadDir(tempReferenceTemplateDir)
if !valid {
impl.logger.Errorw("invalid chart at ", "dir", tempReferenceTemplateDir)
return nil, "", fmt.Errorf("invalid base chart")
}
chart, err := impl.overrideChartMetaDataInDir(tempReferenceTemplateDir, chartMetaData)
if err != nil {
impl.logger.Errorw("error in loading chart dir", "err", err, "dir", tempReferenceTemplateDir)
impl.logger.Errorw("error in overriding chart metadata", "chartPath", tempReferenceTemplateDir, "err", err)
return nil, "", err
}

archivePath, err := chartutil.Save(chart, tempReferenceTemplateDir)
if err != nil {
impl.logger.Errorw("error in saving", "err", err, "dir", tempReferenceTemplateDir)
return nil, "", err
}
impl.logger.Debugw("chart archive path", "path", archivePath)
var valuesYaml string
byteValues, err := json.Marshal(chart.Values)
if err != nil {
impl.logger.Errorw("error in json Marshal values", "values", chart.Values, "err", err)
return nil, "", err
}
if chart.Values != nil {
valuesYaml = chart.Values.Raw
valuesYaml = string(byteValues)
} else {
impl.logger.Warnw("values.yaml not found in helm chart", "dir", tempReferenceTemplateDir)
}
Expand All @@ -339,7 +354,7 @@ func (impl ChartTemplateServiceImpl) GetDir() string {

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

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

func (impl ChartTemplateServiceImpl) LoadChartFromDir(dir string) (*chart.Chart, error) {
//this function is removed in latest helm release and is replaced by Loader in loader package
chart, err := chartutil.LoadDir(dir)
chart, err := loader.LoadDir(dir)
if err != nil {
impl.logger.Errorw("error in loading chart dir", "err", err, "dir")
return chart, err
Expand Down
10 changes: 5 additions & 5 deletions internal/util/ChartTemplateService_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ package util
import (
"context"
"github.com/stretchr/testify/assert"
"k8s.io/helm/pkg/chartutil"
chart2 "k8s.io/helm/pkg/proto/hapi/chart"
"helm.sh/helm/v3/pkg/chart"
"helm.sh/helm/v3/pkg/chartutil"
"math/rand"
"testing"
)
Expand All @@ -47,7 +47,7 @@ func TestChartTemplateService(t *testing.T) {
logger: logger,
randSource: rand.NewSource(0),
}
chartMetaData := &chart2.Metadata{
chartMetaData := &chart.Metadata{
Name: "sample-app",
Version: "1.0.0",
}
Expand All @@ -69,7 +69,7 @@ func TestChartTemplateService(t *testing.T) {
logger: logger,
randSource: rand.NewSource(0),
}
chartMetaData := &chart2.Metadata{
chartMetaData := &chart.Metadata{
Name: "sample-app",
Version: "1.0.0",
}
Expand All @@ -92,7 +92,7 @@ func TestChartTemplateService(t *testing.T) {
logger: logger,
randSource: rand.NewSource(0),
}
chartMetaData := &chart2.Metadata{
chartMetaData := &chart.Metadata{
Name: "sample-app",
Version: "1.0.0",
}
Expand Down
2 changes: 1 addition & 1 deletion internal/util/mocks/ChartTemplateService.go

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

2 changes: 1 addition & 1 deletion pkg/appStore/installedApp/adapter/Adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"github.com/devtron-labs/devtron/internal/util"
appStoreBean "github.com/devtron-labs/devtron/pkg/appStore/bean"
"github.com/devtron-labs/devtron/pkg/deployment/gitOps/git/bean"
"k8s.io/helm/pkg/proto/hapi/chart"
"helm.sh/helm/v3/pkg/chart"
"path"
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
appStoreBean "github.com/devtron-labs/devtron/pkg/appStore/bean"
appStoreDiscoverRepository "github.com/devtron-labs/devtron/pkg/appStore/discover/repository"
"go.uber.org/zap"
"k8s.io/helm/pkg/chartutil"
"helm.sh/helm/v3/pkg/chartutil"
"sigs.k8s.io/yaml"
)

Expand Down
2 changes: 1 addition & 1 deletion pkg/chart/ChartService.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ import (
"github.com/juju/errors"
"go.opentelemetry.io/otel"
"go.uber.org/zap"
"k8s.io/helm/pkg/proto/hapi/chart"
"helm.sh/helm/v3/pkg/chart"
"path/filepath"
"sigs.k8s.io/yaml"
"strconv"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
bean4 "github.com/devtron-labs/devtron/pkg/deployment/manifest/deploymentTemplate/chartRef/bean"
"go.opentelemetry.io/otel"
"go.uber.org/zap"
chart2 "k8s.io/helm/pkg/proto/hapi/chart"
"helm.sh/helm/v3/pkg/chart"
"os"
"path"
"path/filepath"
Expand Down Expand Up @@ -66,7 +66,7 @@ func (impl *DeploymentTemplateServiceImpl) BuildChartAndGetPath(appName string,
return "", err
}
}
chartMetaData := &chart2.Metadata{
chartMetaData := &chart.Metadata{
Name: appName,
Version: envOverride.Chart.ChartVersion,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ import (
dirCopy "github.com/otiai10/copy"
"go.uber.org/zap"
"golang.org/x/exp/maps"
"helm.sh/helm/v3/pkg/chart"
"helm.sh/helm/v3/pkg/chartutil"
"io/ioutil"
"k8s.io/helm/pkg/chartutil"
chart2 "k8s.io/helm/pkg/proto/hapi/chart"
"os"
"path"
"path/filepath"
Expand Down Expand Up @@ -375,7 +375,7 @@ func (impl *ChartRefServiceImpl) GetChartBytesForApps(ctx context.Context, appId

refAppIds := chartRefIdTOAppIds[chartRef.Id]
for _, appId := range refAppIds {
chartMetaData := &chart2.Metadata{
chartMetaData := &chart.Metadata{
Name: appIdToAppName[appId],
Version: chartRefToChartVersion[chartRef.Id],
}
Expand Down
Loading
Loading