diff --git a/api/helm-app/gRPC/applist.pb.go b/api/helm-app/gRPC/applist.pb.go index 508317a95d..21559536bf 100644 --- a/api/helm-app/gRPC/applist.pb.go +++ b/api/helm-app/gRPC/applist.pb.go @@ -2242,6 +2242,7 @@ type UpgradeReleaseRequest struct { HistoryMax int32 `protobuf:"varint,3,opt,name=historyMax,proto3" json:"historyMax,omitempty"` ChartContent *ChartContent `protobuf:"bytes,4,opt,name=chartContent,proto3" json:"chartContent,omitempty"` RunInCtx bool `protobuf:"varint,5,opt,name=RunInCtx,proto3" json:"RunInCtx,omitempty"` + K8SVersion string `protobuf:"bytes,6,opt,name=K8sVersion,proto3" json:"K8sVersion,omitempty"` } func (x *UpgradeReleaseRequest) Reset() { @@ -2311,6 +2312,13 @@ func (x *UpgradeReleaseRequest) GetRunInCtx() bool { return false } +func (x *UpgradeReleaseRequest) GetK8SVersion() string { + if x != nil { + return x.K8SVersion + } + return "" +} + type UpgradeReleaseResponse struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache @@ -2871,6 +2879,7 @@ type HelmInstallCustomRequest struct { ChartContent *ChartContent `protobuf:"bytes,2,opt,name=chartContent,proto3" json:"chartContent,omitempty"` ReleaseIdentifier *ReleaseIdentifier `protobuf:"bytes,3,opt,name=releaseIdentifier,proto3" json:"releaseIdentifier,omitempty"` RunInCtx bool `protobuf:"varint,4,opt,name=RunInCtx,proto3" json:"RunInCtx,omitempty"` + K8SVersion string `protobuf:"bytes,5,opt,name=K8sVersion,proto3" json:"K8sVersion,omitempty"` } func (x *HelmInstallCustomRequest) Reset() { @@ -2933,6 +2942,13 @@ func (x *HelmInstallCustomRequest) GetRunInCtx() bool { return false } +func (x *HelmInstallCustomRequest) GetK8SVersion() string { + if x != nil { + return x.K8SVersion + } + return "" +} + type HelmInstallCustomResponse struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache @@ -3789,7 +3805,7 @@ var file_api_helm_app_gRPC_applist_proto_rawDesc = []byte{ 0x28, 0x09, 0x52, 0x0b, 0x72, 0x65, 0x6c, 0x65, 0x61, 0x73, 0x65, 0x4e, 0x61, 0x6d, 0x65, 0x12, 0x2a, 0x0a, 0x10, 0x72, 0x65, 0x6c, 0x65, 0x61, 0x73, 0x65, 0x4e, 0x61, 0x6d, 0x65, 0x73, 0x70, 0x61, 0x63, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x10, 0x72, 0x65, 0x6c, 0x65, 0x61, - 0x73, 0x65, 0x4e, 0x61, 0x6d, 0x65, 0x73, 0x70, 0x61, 0x63, 0x65, 0x22, 0xe8, 0x01, 0x0a, 0x15, + 0x73, 0x65, 0x4e, 0x61, 0x6d, 0x65, 0x73, 0x70, 0x61, 0x63, 0x65, 0x22, 0x88, 0x02, 0x0a, 0x15, 0x55, 0x70, 0x67, 0x72, 0x61, 0x64, 0x65, 0x52, 0x65, 0x6c, 0x65, 0x61, 0x73, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x40, 0x0a, 0x11, 0x72, 0x65, 0x6c, 0x65, 0x61, 0x73, 0x65, 0x49, 0x64, 0x65, 0x6e, 0x74, 0x69, 0x66, 0x69, 0x65, 0x72, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, @@ -3804,7 +3820,9 @@ var file_api_helm_app_gRPC_applist_proto_rawDesc = []byte{ 0x43, 0x68, 0x61, 0x72, 0x74, 0x43, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x52, 0x0c, 0x63, 0x68, 0x61, 0x72, 0x74, 0x43, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x12, 0x1a, 0x0a, 0x08, 0x52, 0x75, 0x6e, 0x49, 0x6e, 0x43, 0x74, 0x78, 0x18, 0x05, 0x20, 0x01, 0x28, 0x08, 0x52, 0x08, 0x52, 0x75, - 0x6e, 0x49, 0x6e, 0x43, 0x74, 0x78, 0x22, 0x32, 0x0a, 0x16, 0x55, 0x70, 0x67, 0x72, 0x61, 0x64, + 0x6e, 0x49, 0x6e, 0x43, 0x74, 0x78, 0x12, 0x1e, 0x0a, 0x0a, 0x4b, 0x38, 0x73, 0x56, 0x65, 0x72, + 0x73, 0x69, 0x6f, 0x6e, 0x18, 0x06, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x4b, 0x38, 0x73, 0x56, + 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x22, 0x32, 0x0a, 0x16, 0x55, 0x70, 0x67, 0x72, 0x61, 0x64, 0x65, 0x52, 0x65, 0x6c, 0x65, 0x61, 0x73, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x73, 0x75, 0x63, 0x63, 0x65, 0x73, 0x73, 0x18, 0x01, 0x20, 0x01, 0x28, 0x08, 0x52, 0x07, 0x73, 0x75, 0x63, 0x63, 0x65, 0x73, 0x73, 0x22, 0x89, 0x01, 0x0a, 0x17, 0x44, @@ -3879,7 +3897,7 @@ var file_api_helm_app_gRPC_applist_proto_rawDesc = []byte{ 0x43, 0x68, 0x61, 0x72, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x2c, 0x0a, 0x11, 0x67, 0x65, 0x6e, 0x65, 0x72, 0x61, 0x74, 0x65, 0x64, 0x4d, 0x61, 0x6e, 0x69, 0x66, 0x65, 0x73, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x11, 0x67, 0x65, 0x6e, 0x65, 0x72, 0x61, - 0x74, 0x65, 0x64, 0x4d, 0x61, 0x6e, 0x69, 0x66, 0x65, 0x73, 0x74, 0x22, 0xcb, 0x01, 0x0a, 0x18, + 0x74, 0x65, 0x64, 0x4d, 0x61, 0x6e, 0x69, 0x66, 0x65, 0x73, 0x74, 0x22, 0xeb, 0x01, 0x0a, 0x18, 0x48, 0x65, 0x6c, 0x6d, 0x49, 0x6e, 0x73, 0x74, 0x61, 0x6c, 0x6c, 0x43, 0x75, 0x73, 0x74, 0x6f, 0x6d, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x1e, 0x0a, 0x0a, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x73, 0x59, 0x61, 0x6d, 0x6c, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x76, 0x61, @@ -3892,7 +3910,9 @@ var file_api_helm_app_gRPC_applist_proto_rawDesc = []byte{ 0x49, 0x64, 0x65, 0x6e, 0x74, 0x69, 0x66, 0x69, 0x65, 0x72, 0x52, 0x11, 0x72, 0x65, 0x6c, 0x65, 0x61, 0x73, 0x65, 0x49, 0x64, 0x65, 0x6e, 0x74, 0x69, 0x66, 0x69, 0x65, 0x72, 0x12, 0x1a, 0x0a, 0x08, 0x52, 0x75, 0x6e, 0x49, 0x6e, 0x43, 0x74, 0x78, 0x18, 0x04, 0x20, 0x01, 0x28, 0x08, 0x52, - 0x08, 0x52, 0x75, 0x6e, 0x49, 0x6e, 0x43, 0x74, 0x78, 0x22, 0x35, 0x0a, 0x19, 0x48, 0x65, 0x6c, + 0x08, 0x52, 0x75, 0x6e, 0x49, 0x6e, 0x43, 0x74, 0x78, 0x12, 0x1e, 0x0a, 0x0a, 0x4b, 0x38, 0x73, + 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x4b, + 0x38, 0x73, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x22, 0x35, 0x0a, 0x19, 0x48, 0x65, 0x6c, 0x6d, 0x49, 0x6e, 0x73, 0x74, 0x61, 0x6c, 0x6c, 0x43, 0x75, 0x73, 0x74, 0x6f, 0x6d, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x73, 0x75, 0x63, 0x63, 0x65, 0x73, 0x73, 0x18, 0x01, 0x20, 0x01, 0x28, 0x08, 0x52, 0x07, 0x73, 0x75, 0x63, 0x63, 0x65, 0x73, 0x73, diff --git a/api/helm-app/gRPC/applist.proto b/api/helm-app/gRPC/applist.proto index 25b665bb31..22f17d48ee 100644 --- a/api/helm-app/gRPC/applist.proto +++ b/api/helm-app/gRPC/applist.proto @@ -258,6 +258,7 @@ message UpgradeReleaseRequest { int32 historyMax = 3; ChartContent chartContent = 4; bool RunInCtx = 5; + string K8sVersion = 6; } message UpgradeReleaseResponse { @@ -317,6 +318,7 @@ message HelmInstallCustomRequest { ChartContent chartContent = 2; ReleaseIdentifier releaseIdentifier = 3; bool RunInCtx = 4; + string K8sVersion = 5; } message HelmInstallCustomResponse { diff --git a/api/helm-app/service/HelmAppService.go b/api/helm-app/service/HelmAppService.go index 36b6cf7277..86136afae2 100644 --- a/api/helm-app/service/HelmAppService.go +++ b/api/helm-app/service/HelmAppService.go @@ -57,9 +57,11 @@ type HelmAppService interface { GetDesiredManifest(ctx context.Context, app *AppIdentifier, resource *openapi.ResourceIdentifier) (*openapi.DesiredManifestResponse, error) DeleteApplication(ctx context.Context, app *AppIdentifier) (*openapi.UninstallReleaseResponse, error) DeleteDBLinkedHelmApplication(ctx context.Context, app *AppIdentifier, useId int32) (*openapi.UninstallReleaseResponse, error) + // UpdateApplication is a wrapper over helmAppClient.UpdateApplication, sends update request to kubelink for external chart store apps UpdateApplication(ctx context.Context, app *AppIdentifier, request *bean.UpdateApplicationRequestDto) (*openapi.UpdateReleaseResponse, error) GetDeploymentDetail(ctx context.Context, app *AppIdentifier, version int32) (*openapi.HelmAppDeploymentManifestDetail, error) InstallRelease(ctx context.Context, clusterId int, installReleaseRequest *gRPC.InstallReleaseRequest) (*gRPC.InstallReleaseResponse, error) + // UpdateApplicationWithChartInfo is a wrapper over helmAppClient.UpdateApplicationWithChartInfo sends update request to kubelink for helm chart store apps UpdateApplicationWithChartInfo(ctx context.Context, clusterId int, request *bean.UpdateApplicationWithChartInfoRequestDto) (*openapi.UpdateReleaseResponse, error) IsReleaseInstalled(ctx context.Context, app *AppIdentifier) (bool, error) RollbackRelease(ctx context.Context, app *AppIdentifier, version int32) (bool, error) diff --git a/env_gen.md b/env_gen.md index ea8c8de083..7b220f4793 100644 --- a/env_gen.md +++ b/env_gen.md @@ -196,9 +196,9 @@ | REQ_CI_MEM | 3G | | | RESOURCE_LIST_FOR_REPLICAS | Deployment,Rollout,StatefulSet,ReplicaSet | | | RESOURCE_LIST_FOR_REPLICAS_BATCH_SIZE | 5 | | - | REVISION_HISTORY_LIMIT_DEVTRON_APP | 0 | | + | REVISION_HISTORY_LIMIT_DEVTRON_APP | 1 | | | REVISION_HISTORY_LIMIT_EXTERNAL_HELM_APP | 0 | | - | REVISION_HISTORY_LIMIT_HELM_APP | 0 | | + | REVISION_HISTORY_LIMIT_HELM_APP | 1 | | | RUNTIME_CONFIG_LOCAL_DEV | false | | | RUN_HELM_INSTALL_IN_ASYNC_MODE_HELM_APPS | false | | | SCOPED_VARIABLE_ENABLED | false | | diff --git a/pkg/deployment/trigger/devtronApps/TriggerService.go b/pkg/deployment/trigger/devtronApps/TriggerService.go index 8ca1e89a51..24c2402135 100644 --- a/pkg/deployment/trigger/devtronApps/TriggerService.go +++ b/pkg/deployment/trigger/devtronApps/TriggerService.go @@ -42,6 +42,7 @@ import ( clientErrors "github.com/devtron-labs/devtron/pkg/errors" "github.com/devtron-labs/devtron/pkg/eventProcessor/out" "github.com/devtron-labs/devtron/pkg/imageDigestPolicy" + k8s2 "github.com/devtron-labs/devtron/pkg/k8s" "github.com/devtron-labs/devtron/pkg/pipeline" bean8 "github.com/devtron-labs/devtron/pkg/pipeline/bean" "github.com/devtron-labs/devtron/pkg/pipeline/history" @@ -64,6 +65,7 @@ import ( "k8s.io/helm/pkg/proto/hapi/chart" "net/http" "path" + "regexp" "strconv" "strings" "time" @@ -137,6 +139,7 @@ type TriggerServiceImpl struct { ciPipelineRepository pipelineConfig.CiPipelineRepository appWorkflowRepository appWorkflow.AppWorkflowRepository dockerArtifactStoreRepository repository4.DockerArtifactStoreRepository + K8sUtil *util5.K8sServiceImpl } func NewTriggerServiceImpl(logger *zap.SugaredLogger, cdWorkflowCommonService cd.CdWorkflowCommonService, @@ -186,7 +189,8 @@ func NewTriggerServiceImpl(logger *zap.SugaredLogger, cdWorkflowCommonService cd ciPipelineRepository pipelineConfig.CiPipelineRepository, appWorkflowRepository appWorkflow.AppWorkflowRepository, dockerArtifactStoreRepository repository4.DockerArtifactStoreRepository, - imageScanService security2.ImageScanService) (*TriggerServiceImpl, error) { + imageScanService security2.ImageScanService, + K8sUtil *util5.K8sServiceImpl) (*TriggerServiceImpl, error) { impl := &TriggerServiceImpl{ logger: logger, cdWorkflowCommonService: cdWorkflowCommonService, @@ -237,6 +241,7 @@ func NewTriggerServiceImpl(logger *zap.SugaredLogger, cdWorkflowCommonService cd appWorkflowRepository: appWorkflowRepository, dockerArtifactStoreRepository: dockerArtifactStoreRepository, imageScanService: imageScanService, + K8sUtil: K8sUtil, } config, err := types.GetCdConfig() if err != nil { @@ -877,9 +882,23 @@ func (impl *TriggerServiceImpl) createHelmAppForCdPipeline(overrideRequest *bean Name: pipeline.App.AppName, Version: envOverride.Chart.ChartVersion, } - referenceTemplatePath := path.Join(bean5.RefChartDirPath, envOverride.Chart.ReferenceTemplate) + referenceTemplate := envOverride.Chart.ReferenceTemplate + referenceTemplatePath := path.Join(bean5.RefChartDirPath, referenceTemplate) if util.IsHelmApp(pipeline.DeploymentAppType) { + var sanitizedK8sVersion string + //handle specific case for all cronjob charts from cronjob-chart_1-2-0 to cronjob-chart_1-5-0 where semverCompare + //comparison func has wrong api version mentioned, so for already installed charts via these charts that comparison + //is always false, handles the gh issue:- https://github.com/devtron-labs/devtron/issues/4860 + cronJobChartRegex := regexp.MustCompile(bean.CronJobChartRegexExpression) + if cronJobChartRegex.MatchString(referenceTemplate) { + k8sServerVersion, err := impl.K8sUtil.GetKubeVersion() + if err != nil { + impl.logger.Errorw("exception caught in getting k8sServerVersion", "err", err) + return false, err + } + sanitizedK8sVersion = k8s2.StripPrereleaseFromK8sVersion(k8sServerVersion.String()) + } referenceChartByte := envOverride.Chart.ReferenceChart // here updating reference chart into database. if len(envOverride.Chart.ReferenceChart) == 0 { @@ -927,6 +946,9 @@ func (impl *TriggerServiceImpl) createHelmAppForCdPipeline(overrideRequest *bean HistoryMax: impl.helmAppService.GetRevisionHistoryMaxValue(bean6.SOURCE_DEVTRON_APP), ChartContent: &gRPC.ChartContent{Content: referenceChartByte}, } + if len(sanitizedK8sVersion) > 0 { + req.K8SVersion = sanitizedK8sVersion + } if impl.isDevtronAsyncInstallModeEnabled(bean.Helm) { req.RunInCtx = true } @@ -948,7 +970,7 @@ func (impl *TriggerServiceImpl) createHelmAppForCdPipeline(overrideRequest *bean } else { - helmResponse, err := impl.helmInstallReleaseWithCustomChart(ctx, releaseIdentifier, referenceChartByte, mergeAndSave) + helmResponse, err := impl.helmInstallReleaseWithCustomChart(ctx, releaseIdentifier, referenceChartByte, mergeAndSave, sanitizedK8sVersion) // For connection related errors, no need to update the db if err != nil && strings.Contains(err.Error(), "connection error") { @@ -1154,13 +1176,16 @@ func (impl *TriggerServiceImpl) updatePipeline(pipeline *pipelineConfig.Pipeline } // helmInstallReleaseWithCustomChart performs helm install with custom chart -func (impl *TriggerServiceImpl) helmInstallReleaseWithCustomChart(ctx context.Context, releaseIdentifier *gRPC.ReleaseIdentifier, referenceChartByte []byte, valuesYaml string) (*gRPC.HelmInstallCustomResponse, error) { +func (impl *TriggerServiceImpl) helmInstallReleaseWithCustomChart(ctx context.Context, releaseIdentifier *gRPC.ReleaseIdentifier, referenceChartByte []byte, valuesYaml string, k8sServerVersion string) (*gRPC.HelmInstallCustomResponse, error) { helmInstallRequest := gRPC.HelmInstallCustomRequest{ ValuesYaml: valuesYaml, ChartContent: &gRPC.ChartContent{Content: referenceChartByte}, ReleaseIdentifier: releaseIdentifier, } + if len(k8sServerVersion) > 0 { + helmInstallRequest.K8SVersion = k8sServerVersion + } if impl.isDevtronAsyncInstallModeEnabled(bean.Helm) { helmInstallRequest.RunInCtx = true } diff --git a/pkg/deployment/trigger/devtronApps/bean/bean.go b/pkg/deployment/trigger/devtronApps/bean/bean.go index 8c29f86b65..c48924fb0a 100644 --- a/pkg/deployment/trigger/devtronApps/bean/bean.go +++ b/pkg/deployment/trigger/devtronApps/bean/bean.go @@ -60,3 +60,7 @@ type VulnerabilityCheckRequest struct { ImageDigest string CdPipeline *pipelineConfig.Pipeline } + +const ( + CronJobChartRegexExpression = "cronjob-chart_1-(2|3|4|5)-0" +) diff --git a/pkg/generateManifest/DeployementTemplateService.go b/pkg/generateManifest/DeployementTemplateService.go index c1009448d3..3a0df6e293 100644 --- a/pkg/generateManifest/DeployementTemplateService.go +++ b/pkg/generateManifest/DeployementTemplateService.go @@ -15,6 +15,8 @@ import ( "github.com/devtron-labs/devtron/pkg/chart" repository3 "github.com/devtron-labs/devtron/pkg/cluster/repository" "github.com/devtron-labs/devtron/pkg/deployment/manifest/deploymentTemplate/chartRef" + bean2 "github.com/devtron-labs/devtron/pkg/deployment/trigger/devtronApps/bean" + k8s2 "github.com/devtron-labs/devtron/pkg/k8s" "github.com/devtron-labs/devtron/pkg/pipeline" "github.com/devtron-labs/devtron/pkg/pipeline/history" "github.com/devtron-labs/devtron/pkg/resourceQualifiers" @@ -25,6 +27,7 @@ import ( "go.uber.org/zap" "net/http" "os" + "regexp" "strconv" "time" ) @@ -336,11 +339,21 @@ func (impl DeploymentTemplateServiceImpl) GenerateManifest(ctx context.Context, impl.Logger.Errorw("exception caught in getting k8sServerVersion", "err", err) return nil, err } + + sanitizedK8sVersion := k8sServerVersion.String() + //handle specific case for all cronjob charts from cronjob-chart_1-2-0 to cronjob-chart_1-5-0 where semverCompare + //comparison func has wrong api version mentioned, so for already installed charts via these charts that comparison + //is always false, handles the gh issue:- https://github.com/devtron-labs/devtron/issues/4860 + cronJobChartRegex := regexp.MustCompile(bean2.CronJobChartRegexExpression) + if cronJobChartRegex.MatchString(template) { + sanitizedK8sVersion = k8s2.StripPrereleaseFromK8sVersion(sanitizedK8sVersion) + } + installReleaseRequest := &gRPC.InstallReleaseRequest{ ChartName: template, ChartVersion: version, ValuesYaml: valuesYaml, - K8SVersion: k8sServerVersion.String(), + K8SVersion: sanitizedK8sVersion, ChartRepository: ChartRepository, ReleaseIdentifier: ReleaseIdentifier, ChartContent: &gRPC.ChartContent{ diff --git a/pkg/k8s/helper.go b/pkg/k8s/helper.go index 4917f1fb6a..65a3851cad 100644 --- a/pkg/k8s/helper.go +++ b/pkg/k8s/helper.go @@ -1,8 +1,11 @@ package k8s import ( + "fmt" + "github.com/Masterminds/semver" k8sErrors "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "strings" ) func IsResourceNotFoundErr(err error) bool { @@ -11,3 +14,18 @@ func IsResourceNotFoundErr(err error) bool { } return false } + +// StripPrereleaseFromK8sVersion takes in k8sVersion and stripe pre-release from semver version and return sanitized k8sVersion +// or error if invalid version provided, e.g. if k8sVersion = "1.25.16-eks-b9c9ed7", then it returns "1.25.16". +func StripPrereleaseFromK8sVersion(k8sVersion string) string { + version, err := semver.NewVersion(k8sVersion) + if err != nil { + fmt.Printf("error in stripping pre-release from k8sServerVersion due to invalid k8sServerVersion:= %s, err:= %v", k8sVersion, err) + return k8sVersion + } + if len(version.Prerelease()) > 0 { + stringToReplace := "-" + version.Prerelease() + k8sVersion = strings.Replace(k8sVersion, stringToReplace, "", 1) + } + return k8sVersion +} diff --git a/pkg/k8s/helper_test.go b/pkg/k8s/helper_test.go new file mode 100644 index 0000000000..77455a4d9e --- /dev/null +++ b/pkg/k8s/helper_test.go @@ -0,0 +1,57 @@ +package k8s + +import "testing" + +// not removing metadata from k8s version if exists, we only eliminate pre-release from k8s version +const ( + K8sVersionWithPreRelease = "v1.25.16-eks-b9c9ed7" + K8sVersionWithPreReleaseAndMetadata = "v1.25.16-eks-b9c9ed7+acj23-as" + K8sVersionWithMetadata = "v1.25.16+acj23-as" + K8sVersionWithoutPreReleaseAndMetadata = "v1.25.16" + InvalidK8sVersion = "" +) + +func TestStripPrereleaseFromK8sVersion(t *testing.T) { + type args struct { + k8sVersion string + } + tests := []struct { + name string + args args + want string + }{ + { + name: "Test1_K8sVersionWithPreRelease", + args: args{k8sVersion: K8sVersionWithPreRelease}, + want: K8sVersionWithoutPreReleaseAndMetadata, + }, + { + name: "Test2_K8sVersionWithPreReleaseAndMetadata", + args: args{k8sVersion: K8sVersionWithPreReleaseAndMetadata}, + want: K8sVersionWithMetadata, + }, + { + name: "Test3_K8sVersionWithMetadata", + args: args{k8sVersion: K8sVersionWithMetadata}, + want: K8sVersionWithMetadata, + }, + { + name: "Test4_K8sVersionWithoutPrereleaseAndMetadata", + args: args{k8sVersion: K8sVersionWithoutPreReleaseAndMetadata}, + want: K8sVersionWithoutPreReleaseAndMetadata, + }, + { + name: "Test5_EmptyK8sVersion", + args: args{k8sVersion: InvalidK8sVersion}, + want: InvalidK8sVersion, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got := StripPrereleaseFromK8sVersion(tt.args.k8sVersion) + if got != tt.want { + t.Errorf("StripPrereleaseFromK8sVersion() got = %v, want %v", got, tt.want) + } + }) + } +} diff --git a/wire_gen.go b/wire_gen.go index fa805a35ae..5163df0977 100644 --- a/wire_gen.go +++ b/wire_gen.go @@ -588,7 +588,7 @@ func InitializeApp() (*App, error) { manifestPushConfigRepositoryImpl := repository9.NewManifestPushConfigRepository(sugaredLogger, db) scanToolExecutionHistoryMappingRepositoryImpl := security.NewScanToolExecutionHistoryMappingRepositoryImpl(db, sugaredLogger) imageScanServiceImpl := security2.NewImageScanServiceImpl(sugaredLogger, imageScanHistoryRepositoryImpl, imageScanResultRepositoryImpl, imageScanObjectMetaRepositoryImpl, cveStoreRepositoryImpl, imageScanDeployInfoRepositoryImpl, userServiceImpl, teamRepositoryImpl, appRepositoryImpl, environmentServiceImpl, ciArtifactRepositoryImpl, policyServiceImpl, pipelineRepositoryImpl, ciPipelineRepositoryImpl, scanToolMetadataRepositoryImpl, scanToolExecutionHistoryMappingRepositoryImpl, cvePolicyRepositoryImpl) - triggerServiceImpl, err := devtronApps.NewTriggerServiceImpl(sugaredLogger, cdWorkflowCommonServiceImpl, gitOpsManifestPushServiceImpl, gitOpsConfigReadServiceImpl, argoK8sClientImpl, acdConfig, argoClientWrapperServiceImpl, pipelineStatusTimelineServiceImpl, chartTemplateServiceImpl, chartServiceImpl, workflowEventPublishServiceImpl, manifestCreationServiceImpl, deployedConfigurationHistoryServiceImpl, argoUserServiceImpl, pipelineStageServiceImpl, globalPluginServiceImpl, customTagServiceImpl, pluginInputVariableParserImpl, prePostCdScriptHistoryServiceImpl, scopedVariableCMCSManagerImpl, workflowServiceImpl, imageDigestPolicyServiceImpl, userServiceImpl, clientImpl, helmAppServiceImpl, enforcerUtilImpl, helmAppClientImpl, eventSimpleFactoryImpl, eventRESTClientImpl, environmentVariables, appRepositoryImpl, ciPipelineMaterialRepositoryImpl, imageScanHistoryRepositoryImpl, imageScanDeployInfoRepositoryImpl, pipelineRepositoryImpl, pipelineOverrideRepositoryImpl, manifestPushConfigRepositoryImpl, chartRepositoryImpl, environmentRepositoryImpl, cdWorkflowRepositoryImpl, ciWorkflowRepositoryImpl, ciArtifactRepositoryImpl, ciTemplateServiceImpl, materialRepositoryImpl, appLabelRepositoryImpl, ciPipelineRepositoryImpl, appWorkflowRepositoryImpl, dockerArtifactStoreRepositoryImpl, imageScanServiceImpl) + triggerServiceImpl, err := devtronApps.NewTriggerServiceImpl(sugaredLogger, cdWorkflowCommonServiceImpl, gitOpsManifestPushServiceImpl, gitOpsConfigReadServiceImpl, argoK8sClientImpl, acdConfig, argoClientWrapperServiceImpl, pipelineStatusTimelineServiceImpl, chartTemplateServiceImpl, chartServiceImpl, workflowEventPublishServiceImpl, manifestCreationServiceImpl, deployedConfigurationHistoryServiceImpl, argoUserServiceImpl, pipelineStageServiceImpl, globalPluginServiceImpl, customTagServiceImpl, pluginInputVariableParserImpl, prePostCdScriptHistoryServiceImpl, scopedVariableCMCSManagerImpl, workflowServiceImpl, imageDigestPolicyServiceImpl, userServiceImpl, clientImpl, helmAppServiceImpl, enforcerUtilImpl, helmAppClientImpl, eventSimpleFactoryImpl, eventRESTClientImpl, environmentVariables, appRepositoryImpl, ciPipelineMaterialRepositoryImpl, imageScanHistoryRepositoryImpl, imageScanDeployInfoRepositoryImpl, pipelineRepositoryImpl, pipelineOverrideRepositoryImpl, manifestPushConfigRepositoryImpl, chartRepositoryImpl, environmentRepositoryImpl, cdWorkflowRepositoryImpl, ciWorkflowRepositoryImpl, ciArtifactRepositoryImpl, ciTemplateServiceImpl, materialRepositoryImpl, appLabelRepositoryImpl, ciPipelineRepositoryImpl, appWorkflowRepositoryImpl, dockerArtifactStoreRepositoryImpl, imageScanServiceImpl, k8sServiceImpl) if err != nil { return nil, err }