From 32d8a042eab595cb5bf2f3a7ecb9264498f6b127 Mon Sep 17 00:00:00 2001 From: Dharmit Shah Date: Mon, 14 Feb 2022 17:22:36 +0530 Subject: [PATCH] Set replicas using devfile library (#5413) --- go.mod | 5 ++--- go.sum | 7 +++---- pkg/devfile/adapters/kubernetes/component/adapter.go | 6 +++--- .../devfile/library/pkg/devfile/generator/generators.go | 3 ++- .../devfile/library/pkg/devfile/generator/utils.go | 2 ++ vendor/modules.txt | 4 ++-- 6 files changed, 14 insertions(+), 13 deletions(-) diff --git a/go.mod b/go.mod index bd0215b591f..80f59a10d74 100644 --- a/go.mod +++ b/go.mod @@ -7,8 +7,8 @@ require ( github.com/Netflix/go-expect v0.0.0-20201125194554-85d881c3777e github.com/Xuanwo/go-locale v1.0.0 github.com/blang/semver v3.5.1+incompatible - github.com/devfile/api/v2 v2.0.0-20220126144139-f6d7cd85a481 - github.com/devfile/library v1.2.1-0.20220201022328-58ef0b78c0fe + github.com/devfile/api/v2 v2.0.0-20220117162434-6e6e6a8bc14c + github.com/devfile/library v1.2.1-0.20220201144851-0749c7fa35a1 github.com/devfile/registry-support/index/generator v0.0.0-20211012185733-0a73f866043f github.com/devfile/registry-support/registry-library v0.0.0-20211125162259-d7edf148d3e2 github.com/fatih/color v1.10.0 @@ -76,5 +76,4 @@ replace ( k8s.io/component-helpers => k8s.io/component-helpers v0.0.0-20211006165314-dacad8cb3fcb k8s.io/kubectl => github.com/openshift/kubernetes/staging/src/k8s.io/kubectl v0.0.0-20210831004331-1199c36daed6 k8s.io/metrics => k8s.io/metrics v0.0.0-20211006171351-de75bc981086 - ) diff --git a/go.sum b/go.sum index 8eb2e8d4856..2d06432e2f6 100644 --- a/go.sum +++ b/go.sum @@ -262,12 +262,11 @@ github.com/deislabs/oras v0.8.1/go.mod h1:Mx0rMSbBNaNfY9hjpccEnxkOqJL6KGjtxNHPLC github.com/denisenkom/go-mssqldb v0.0.0-20190515213511-eb9f6a1743f3/go.mod h1:zAg7JM8CkOJ43xKXIj7eRO9kmWm/TW578qo+oDO6tuM= github.com/denverdino/aliyungo v0.0.0-20190125010748-a747050bb1ba/go.mod h1:dV8lFg6daOBZbT6/BDGIz6Y3WFGn8juu6G+CQ6LHtl0= github.com/devfile/api/v2 v2.0.0-20210910153124-da620cd1a7a1/go.mod h1:kLX/nW93gigOHXK3NLeJL2fSS/sgEe+OHu8bo3aoOi4= +github.com/devfile/api/v2 v2.0.0-20220117162434-6e6e6a8bc14c h1:sjghKUov/WT71dBreHYQcTgQctxHT/p4uAhUFdGQfSU= github.com/devfile/api/v2 v2.0.0-20220117162434-6e6e6a8bc14c/go.mod h1:d99eTN6QxgzihOOFyOZA+VpUyD4Q1pYRYHZ/ci9J96Q= -github.com/devfile/api/v2 v2.0.0-20220126144139-f6d7cd85a481 h1:G4trvnLOua7AsSetNa8k4u9VUNavPIwXa3CNfBwQwx4= -github.com/devfile/api/v2 v2.0.0-20220126144139-f6d7cd85a481/go.mod h1:kLX/nW93gigOHXK3NLeJL2fSS/sgEe+OHu8bo3aoOi4= github.com/devfile/library v1.1.1-0.20210910214722-7c5ff63711ec/go.mod h1:svPWwWb+BP15SXCHl0dyOeE4Sohrjl5a2BaOzc/riLc= -github.com/devfile/library v1.2.1-0.20220201022328-58ef0b78c0fe h1:IzpRD2XS7m7k+6lFLYjaFAPYy0CSv0861teFvzNFkdM= -github.com/devfile/library v1.2.1-0.20220201022328-58ef0b78c0fe/go.mod h1:Fp8wxWPVA5pz8geGIp0DioGVgnZAdwyqsgohvRaR5rk= +github.com/devfile/library v1.2.1-0.20220201144851-0749c7fa35a1 h1:cenRsPWEfoCvKit8AtYnPtVlxA5z9EyVDqK3JW62er4= +github.com/devfile/library v1.2.1-0.20220201144851-0749c7fa35a1/go.mod h1:nZ9P4D8QxHdWe/czYx9sn+BxzsTOXMj/LAUfcqkvvuU= github.com/devfile/registry-support/index/generator v0.0.0-20211012185733-0a73f866043f h1:fKNUmoOPh7yAs69uMRZWHvev+m3e7T4jBL/hOXZB9ys= github.com/devfile/registry-support/index/generator v0.0.0-20211012185733-0a73f866043f/go.mod h1:bLGagbW2SFn7jo5+kUPlCMehIGqWkRtLKc5O0OyJMJM= github.com/devfile/registry-support/registry-library v0.0.0-20211125162259-d7edf148d3e2 h1:Rwuc0bdx8xSZWdIwXjAxaKYnZIWHneJmDAAZ6a5jXzY= diff --git a/pkg/devfile/adapters/kubernetes/component/adapter.go b/pkg/devfile/adapters/kubernetes/component/adapter.go index 92f86241f00..c359ac0720a 100644 --- a/pkg/devfile/adapters/kubernetes/component/adapter.go +++ b/pkg/devfile/adapters/kubernetes/component/adapter.go @@ -3,6 +3,7 @@ package component import ( "fmt" "io" + "k8s.io/utils/pointer" "os" "reflect" "strings" @@ -10,6 +11,7 @@ import ( "github.com/pkg/errors" + "github.com/devfile/library/pkg/devfile/generator" "github.com/redhat-developer/odo/pkg/component" componentlabels "github.com/redhat-developer/odo/pkg/component/labels" "github.com/redhat-developer/odo/pkg/devfile" @@ -26,7 +28,6 @@ import ( "github.com/redhat-developer/odo/pkg/util" devfilev1 "github.com/devfile/api/v2/pkg/apis/workspaces/v1alpha2" - "github.com/devfile/library/pkg/devfile/generator" parsercommon "github.com/devfile/library/pkg/devfile/parser/data/v2/common" dfutil "github.com/devfile/library/pkg/util" @@ -35,7 +36,6 @@ import ( kerrors "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/klog" - "k8s.io/utils/pointer" ) const supervisorDStatusWaitTimeInterval = 1 @@ -532,13 +532,13 @@ func (a *Adapter) createOrUpdateComponent(componentExists bool, ei envinfo.EnvSp Containers: containers, Volumes: allVolumes, PodSelectorLabels: selectorLabels, + Replicas: pointer.Int32Ptr(1), } deployment, err := generator.GetDeployment(a.Devfile, deployParams) if err != nil { return err } - deployment.Spec.Replicas = pointer.Int32Ptr(1) if deployment.Annotations == nil { deployment.Annotations = make(map[string]string) } diff --git a/vendor/github.com/devfile/library/pkg/devfile/generator/generators.go b/vendor/github.com/devfile/library/pkg/devfile/generator/generators.go index 6a2c5a18224..7ceafc19320 100644 --- a/vendor/github.com/devfile/library/pkg/devfile/generator/generators.go +++ b/vendor/github.com/devfile/library/pkg/devfile/generator/generators.go @@ -2,7 +2,6 @@ package generator import ( "fmt" - v1 "github.com/devfile/api/v2/pkg/apis/workspaces/v1alpha2" "github.com/devfile/library/pkg/devfile/parser" "github.com/devfile/library/pkg/devfile/parser/data/v2/common" @@ -158,6 +157,7 @@ type DeploymentParams struct { Containers []corev1.Container Volumes []corev1.Volume PodSelectorLabels map[string]string + Replicas *int32 } // GetDeployment gets a deployment object @@ -173,6 +173,7 @@ func GetDeployment(devfileObj parser.DevfileObj, deployParams DeploymentParams) deploySpecParams := deploymentSpecParams{ PodTemplateSpec: *getPodTemplateSpec(podTemplateSpecParams), PodSelectorLabels: deployParams.PodSelectorLabels, + Replicas: deployParams.Replicas, } containerAnnotations, err := getContainerAnnotations(devfileObj, common.DevfileOptions{}) diff --git a/vendor/github.com/devfile/library/pkg/devfile/generator/utils.go b/vendor/github.com/devfile/library/pkg/devfile/generator/utils.go index 0b1567ae040..35af324302d 100644 --- a/vendor/github.com/devfile/library/pkg/devfile/generator/utils.go +++ b/vendor/github.com/devfile/library/pkg/devfile/generator/utils.go @@ -233,6 +233,7 @@ func getPodTemplateSpec(podTemplateSpecParams podTemplateSpecParams) *corev1.Pod type deploymentSpecParams struct { PodTemplateSpec corev1.PodTemplateSpec PodSelectorLabels map[string]string + Replicas *int32 } // getDeploymentSpec gets a deployment spec @@ -245,6 +246,7 @@ func getDeploymentSpec(deploySpecParams deploymentSpecParams) *appsv1.Deployment MatchLabels: deploySpecParams.PodSelectorLabels, }, Template: deploySpecParams.PodTemplateSpec, + Replicas: deploySpecParams.Replicas, } return deploymentSpec diff --git a/vendor/modules.txt b/vendor/modules.txt index cbcd9341795..d0ec065a6fc 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -96,7 +96,7 @@ github.com/deislabs/oras/pkg/artifact github.com/deislabs/oras/pkg/content github.com/deislabs/oras/pkg/context github.com/deislabs/oras/pkg/oras -# github.com/devfile/api/v2 v2.0.0-20220126144139-f6d7cd85a481 +# github.com/devfile/api/v2 v2.0.0-20220117162434-6e6e6a8bc14c ## explicit github.com/devfile/api/v2/pkg/apis/workspaces/v1alpha2 github.com/devfile/api/v2/pkg/attributes @@ -105,7 +105,7 @@ github.com/devfile/api/v2/pkg/utils/overriding github.com/devfile/api/v2/pkg/utils/unions github.com/devfile/api/v2/pkg/validation github.com/devfile/api/v2/pkg/validation/variables -# github.com/devfile/library v1.2.1-0.20220201022328-58ef0b78c0fe +# github.com/devfile/library v1.2.1-0.20220201144851-0749c7fa35a1 ## explicit github.com/devfile/library/pkg/devfile github.com/devfile/library/pkg/devfile/generator