Skip to content

Commit

Permalink
Add commit id to deploy pipeline job (#549)
Browse files Browse the repository at this point in the history
* Added commit-id to deploy pipeline params

* Fixed unit-tests

* Updated radix-operator ref

* Updated swagger
  • Loading branch information
satr authored Oct 18, 2023
1 parent 9bdd2c0 commit 954732f
Show file tree
Hide file tree
Showing 12 changed files with 54 additions and 31 deletions.
8 changes: 5 additions & 3 deletions api/applications/applications_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@ import (
"context"
"encoding/json"
"fmt"
"github.com/equinor/radix-api/models"
"github.com/equinor/radix-common/utils/pointers"
"net/http"
"net/url"
"os"
"strings"
"testing"
"time"

"github.com/equinor/radix-api/models"
"github.com/equinor/radix-common/utils/pointers"

applicationModels "github.com/equinor/radix-api/api/applications/models"
environmentModels "github.com/equinor/radix-api/api/environments/models"
jobModels "github.com/equinor/radix-api/api/jobs/models"
Expand Down Expand Up @@ -45,6 +46,7 @@ const (
dnsZone = "dev.radix.equinor.com"
appAliasDNSZone = "app.dev.radix.equinor.com"
egressIps = "0.0.0.0"
subscriptionId = "12347718-c8f8-4995-bfbb-02655ff1f89c"
)

func setupTest(requireAppConfigurationItem, requireAppADGroups bool) (*commontest.Utils, *controllertest.Utils, *kubefake.Clientset, *fake.Clientset, prometheusclient.Interface, secretsstorevclient.Interface) {
Expand All @@ -65,7 +67,7 @@ func setupTestWithFactory(handlerFactory ApplicationHandlerFactory) (*commontest

// commonTestUtils is used for creating CRDs
commonTestUtils := commontest.NewTestUtils(kubeclient, radixclient, secretproviderclient)
commonTestUtils.CreateClusterPrerequisites(clusterName, egressIps)
commonTestUtils.CreateClusterPrerequisites(clusterName, egressIps, subscriptionId)
os.Setenv(defaults.ActiveClusternameEnvironmentVariable, clusterName)

// controllerTestUtils is used for issuing HTTP request and processing responses
Expand Down
7 changes: 7 additions & 0 deletions api/applications/models/pipeline_parameters.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,12 @@ type PipelineParametersDeploy struct {
//
// example: [email protected]
TriggeredBy string `json:"triggeredBy,omitempty"`

// CommitID the commit ID of the branch
// OPTIONAL for information only
//
// example: 4faca8595c5283a9d0f17a623b9255a0d9866a2e
CommitID string `json:"commitID"`
}

// MapPipelineParametersDeployToJobParameter maps to JobParameter
Expand All @@ -124,5 +130,6 @@ func (deployParam PipelineParametersDeploy) MapPipelineParametersDeployToJobPara
ToEnvironment: deployParam.ToEnvironment,
TriggeredBy: deployParam.TriggeredBy,
ImageTagNames: deployParam.ImageTagNames,
CommitID: deployParam.CommitID,
}
}
14 changes: 8 additions & 6 deletions api/buildsecrets/buildsecrets_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ package buildsecrets

import (
"fmt"
environmentModels "github.com/equinor/radix-api/api/secrets/models"
"net/http"
secretproviderfake "sigs.k8s.io/secrets-store-csi-driver/pkg/client/clientset/versioned/fake"
"testing"

environmentModels "github.com/equinor/radix-api/api/secrets/models"
secretproviderfake "sigs.k8s.io/secrets-store-csi-driver/pkg/client/clientset/versioned/fake"

"github.com/equinor/radix-api/api/buildsecrets/models"
controllertest "github.com/equinor/radix-api/api/test"
"github.com/equinor/radix-api/api/utils"
Expand All @@ -20,9 +21,10 @@ import (
)

const (
clusterName = "AnyClusterName"
anyAppName = "any-app"
egressIps = "0.0.0.0"
clusterName = "AnyClusterName"
anyAppName = "any-app"
egressIps = "0.0.0.0"
subscriptionId = "12347718-c8f8-4995-bfbb-02655ff1f89c"
)

func setupTest() (*commontest.Utils, *controllertest.Utils, kubernetes.Interface, radixclient.Interface) {
Expand All @@ -33,7 +35,7 @@ func setupTest() (*commontest.Utils, *controllertest.Utils, kubernetes.Interface

// commonTestUtils is used for creating CRDs
commonTestUtils := commontest.NewTestUtils(kubeclient, radixclient, secretproviderclient)
commonTestUtils.CreateClusterPrerequisites(clusterName, egressIps)
commonTestUtils.CreateClusterPrerequisites(clusterName, egressIps, subscriptionId)

// controllerTestUtils is used for issuing HTTP request and processing responses
controllerTestUtils := controllertest.NewTestUtils(kubeclient, radixclient, secretproviderclient, NewBuildSecretsController())
Expand Down
15 changes: 8 additions & 7 deletions api/buildstatus/build_status_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const (
dnsZone = "dev.radix.equinor.com"
appAliasDNSZone = "app.dev.radix.equinor.com"
egressIps = "0.0.0.0"
subscriptionId = "12347718-c8f8-4995-bfbb-02655ff1f89c"
)

func setupTest() (*commontest.Utils, *kubefake.Clientset, *fake.Clientset, *secretproviderfake.Clientset) {
Expand All @@ -36,7 +37,7 @@ func setupTest() (*commontest.Utils, *kubefake.Clientset, *fake.Clientset, *secr

// commonTestUtils is used for creating CRDs
commonTestUtils := commontest.NewTestUtils(kubeclient, radixclient, secretproviderclient)
commonTestUtils.CreateClusterPrerequisites(clusterName, egressIps)
commonTestUtils.CreateClusterPrerequisites(clusterName, egressIps, subscriptionId)
os.Setenv(defaults.ActiveClusternameEnvironmentVariable, clusterName)

return &commonTestUtils, kubeclient, radixclient, secretproviderclient
Expand All @@ -50,32 +51,32 @@ func TestGetBuildStatus(t *testing.T) {
commonTestUtils.ApplyApplication(builders.ARadixApplication().WithAppName("my-app").WithEnvironment("test", "master"))
commonTestUtils.ApplyJob(
builders.NewJobBuilder().WithCreated(jobStartReferenceTime).
WithBranch("master").WithJobName("bd-test-1").WithPipeline(v1.BuildDeploy).WithAppName("my-app").
WithBranch("master").WithJobName("bd-test-1").WithPipelineType(v1.BuildDeploy).WithAppName("my-app").
WithStatus(builders.NewJobStatusBuilder().WithCondition(v1.JobSucceeded).WithStarted(jobStartReferenceTime).WithEnded(jobStartReferenceTime.Add(1 * time.Hour))),
)
commonTestUtils.ApplyJob(
builders.NewJobBuilder().WithCreated(jobStartReferenceTime.Add(1 * time.Hour)).
WithBranch("master").WithJobName("bd-test-2").WithPipeline(v1.BuildDeploy).WithAppName("my-app").
WithBranch("master").WithJobName("bd-test-2").WithPipelineType(v1.BuildDeploy).WithAppName("my-app").
WithStatus(builders.NewJobStatusBuilder().WithCondition(v1.JobRunning).WithStarted(jobStartReferenceTime.Add(2 * time.Hour))),
)
commonTestUtils.ApplyJob(
builders.NewJobBuilder().WithCreated(jobStartReferenceTime).
WithBranch("master").WithJobName("d-test-1").WithPipeline(v1.Deploy).WithAppName("my-app").
WithBranch("master").WithJobName("d-test-1").WithPipelineType(v1.Deploy).WithAppName("my-app").
WithStatus(builders.NewJobStatusBuilder().WithCondition(v1.JobFailed).WithStarted(jobStartReferenceTime).WithEnded(jobStartReferenceTime.Add(1 * time.Hour))),
)
commonTestUtils.ApplyJob(
builders.NewJobBuilder().WithCreated(jobStartReferenceTime.Add(1 * time.Hour)).
WithBranch("master").WithJobName("d-test-2").WithPipeline(v1.Deploy).WithAppName("my-app").
WithBranch("master").WithJobName("d-test-2").WithPipelineType(v1.Deploy).WithAppName("my-app").
WithStatus(builders.NewJobStatusBuilder().WithCondition(v1.JobSucceeded).WithStarted(jobStartReferenceTime.Add(2 * time.Hour))),
)
commonTestUtils.ApplyJob(
builders.NewJobBuilder().WithCreated(jobStartReferenceTime).
WithBranch("master").WithJobName("p-test-1").WithPipeline(v1.Promote).WithAppName("my-app").
WithBranch("master").WithJobName("p-test-1").WithPipelineType(v1.Promote).WithAppName("my-app").
WithStatus(builders.NewJobStatusBuilder().WithCondition(v1.JobStopped).WithStarted(jobStartReferenceTime).WithEnded(jobStartReferenceTime.Add(1 * time.Hour))),
)
commonTestUtils.ApplyJob(
builders.NewJobBuilder().WithCreated(jobStartReferenceTime.Add(1 * time.Hour)).
WithBranch("master").WithJobName("p-test-2").WithPipeline(v1.Promote).WithAppName("my-app").
WithBranch("master").WithJobName("p-test-2").WithPipelineType(v1.Promote).WithAppName("my-app").
WithStatus(builders.NewJobStatusBuilder().WithCondition(v1.JobFailed).WithStarted(jobStartReferenceTime.Add(2 * time.Hour))),
)

Expand Down
3 changes: 2 additions & 1 deletion api/environments/environment_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ const (
anyEnvironment = "dev"
anySecretName = "TEST_SECRET"
egressIps = "0.0.0.0"
subscriptionId = "12347718-c8f8-4995-bfbb-02655ff1f89c"
)

func setupTest(envHandlerOpts []EnvironmentHandlerOptions) (*commontest.Utils, *controllertest.Utils, *controllertest.Utils, kubernetes.Interface, radixclient.Interface, prometheusclient.Interface, secretsstorevclient.Interface) {
Expand All @@ -69,7 +70,7 @@ func setupTest(envHandlerOpts []EnvironmentHandlerOptions) (*commontest.Utils, *

// commonTestUtils is used for creating CRDs
commonTestUtils := commontest.NewTestUtils(kubeclient, radixclient, secretproviderclient)
commonTestUtils.CreateClusterPrerequisites(clusterName, egressIps)
commonTestUtils.CreateClusterPrerequisites(clusterName, egressIps, subscriptionId)

// secretControllerTestUtils is used for issuing HTTP request and processing responses
secretControllerTestUtils := controllertest.NewTestUtils(kubeclient, radixclient, secretproviderclient, secrets.NewSecretController())
Expand Down
5 changes: 3 additions & 2 deletions api/environmentvariables/env_vars_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const (
environmentName = "dev"
componentName = "backend"
egressIps = "0.0.0.0"
subscriptionId = "12347718-c8f8-4995-bfbb-02655ff1f89c"
)

func setupTestWithMockHandler(mockCtrl *gomock.Controller) (*commontest.Utils, *controllertest.Utils, kubernetes.Interface, radixclient.Interface, prometheusclient.Interface, *MockEnvVarsHandler) {
Expand All @@ -51,7 +52,7 @@ func setupTest() (*kubefake.Clientset, *fake.Clientset, *prometheusfake.Clientse

// commonTestUtils is used for creating CRDs
commonTestUtils := commontest.NewTestUtils(kubeclient, radixclient, secretproviderclient)
commonTestUtils.CreateClusterPrerequisites(clusterName, egressIps)
commonTestUtils.CreateClusterPrerequisites(clusterName, egressIps, subscriptionId)
return kubeclient, radixclient, prometheusclient, commonTestUtils, commonTestUtils.GetKubeUtil(), secretproviderclient
}

Expand Down Expand Up @@ -123,7 +124,7 @@ func Test_GetComponentEnvVars(t *testing.T) {
}

func Test_ChangeEnvVar(t *testing.T) {
//setupTestWithMockHandler()
// setupTestWithMockHandler()
ctrl := gomock.NewController(t)
defer ctrl.Finish()

Expand Down
5 changes: 3 additions & 2 deletions api/jobs/start_job_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ const (
)

// HandleStartPipelineJob Handles the creation of a pipeline job for an application
func (jh JobHandler) HandleStartPipelineJob(ctx context.Context, appName string, pipeline *pipelineJob.Definition, jobSpec *jobModels.JobParameters) (*jobModels.JobSummary, error) {
func (jh JobHandler) HandleStartPipelineJob(ctx context.Context, appName string, pipeline *pipelineJob.Definition, jobParameters *jobModels.JobParameters) (*jobModels.JobSummary, error) {
radixRegistration, _ := jh.userAccount.RadixClient.RadixV1().RadixRegistrations().Get(ctx, appName, metav1.GetOptions{})

radixConfigFullName, err := getRadixConfigFullName(radixRegistration)
if err != nil {
return nil, err
}

job := jh.buildPipelineJob(appName, radixRegistration.Spec.CloneURL, radixConfigFullName, pipeline, jobSpec)
job := jh.buildPipelineJob(appName, radixRegistration.Spec.CloneURL, radixConfigFullName, pipeline, jobParameters)
return jh.createPipelineJob(ctx, appName, job)
}

Expand Down Expand Up @@ -95,6 +95,7 @@ func (jh JobHandler) buildPipelineJob(appName, cloneURL, radixConfigFullName str
deploySpec = v1.RadixDeploySpec{
ToEnvironment: jobSpec.ToEnvironment,
ImageTagNames: jobSpec.ImageTagNames,
CommitID: jobSpec.CommitID,
}
}

Expand Down
3 changes: 2 additions & 1 deletion api/secrets/secret_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const (
anyEnvironment = "dev"
anyEnvironmentName = "TEST_SECRET"
egressIps = "0.0.0.0"
subscriptionId = "12347718-c8f8-4995-bfbb-02655ff1f89c"
)

func setupTest() (*commontest.Utils, *controllertest.Utils, kubernetes.Interface, radixclient.Interface, prometheusclient.Interface, secretsstorevclient.Interface) {
Expand All @@ -44,7 +45,7 @@ func setupTest() (*commontest.Utils, *controllertest.Utils, kubernetes.Interface

// commonTestUtils is used for creating CRDs
commonTestUtils := commontest.NewTestUtils(kubeclient, radixclient, secretproviderclient)
commonTestUtils.CreateClusterPrerequisites(clusterName, egressIps)
commonTestUtils.CreateClusterPrerequisites(clusterName, egressIps, subscriptionId)

// secretControllerTestUtils is used for issuing HTTP request and processing responses
secretControllerTestUtils := controllertest.NewTestUtils(kubeclient, radixclient, secretproviderclient, NewSecretController())
Expand Down
13 changes: 7 additions & 6 deletions api/utils/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ import (
)

const (
clusterName = "AnyClusterName"
egressIps = "0.0.0.0"
clusterName = "AnyClusterName"
egressIps = "0.0.0.0"
subscriptionId = "bd9f9eaa-2703-47c6-b5e0-faf4e058df73"
)

func SetupTest() (*commontest.Utils, kubernetes.Interface, radixclient.Interface, prometheusclient.Interface, secretsstorevclient.Interface) {
Expand All @@ -30,7 +31,7 @@ func SetupTest() (*commontest.Utils, kubernetes.Interface, radixclient.Interface

// commonTestUtils is used for creating CRDs
commonTestUtils := commontest.NewTestUtils(kubeClient, radixClient, secretProviderClient)
commonTestUtils.CreateClusterPrerequisites(clusterName, egressIps)
commonTestUtils.CreateClusterPrerequisites(clusterName, egressIps, subscriptionId)

return &commonTestUtils, kubeClient, radixClient, prometheusClient, secretProviderClient
}
Expand All @@ -53,8 +54,8 @@ func ApplyApplicationWithSync(client kubernetes.Interface, radixclient radixclie
kubeUtils, _ := kube.New(client, radixclient, nil)
commonTestUtils.ApplyApplication(applicationBuilder)

applicationconfig, _ := applicationconfig.NewApplicationConfig(client, kubeUtils, radixclient, registrationBuilder.BuildRR(), applicationBuilder.BuildRA())
applicationconfig.OnSync()
applicationConfig, _ := applicationconfig.NewApplicationConfig(client, kubeUtils, radixclient, registrationBuilder.BuildRR(), applicationBuilder.BuildRA())
applicationConfig.OnSync()
}

// ApplyDeploymentWithSync syncs based on deployment builder, and default builders for application and registration.
Expand All @@ -66,6 +67,6 @@ func ApplyDeploymentWithSync(client kubernetes.Interface, radixclient radixclien

kubeUtils, _ := kube.New(client, radixclient, secretproviderclient)
rd, _ := commonTestUtils.ApplyDeployment(deploymentBuilder)
deployment := deployment.NewDeployment(client, kubeUtils, radixclient, promclient, registrationBuilder.BuildRR(), rd, "123456", 443, []deployment.IngressAnnotationProvider{}, []deployment.AuxiliaryResourceManager{})
deployment := deployment.NewDeploymentSyncer(client, kubeUtils, radixclient, promclient, registrationBuilder.BuildRR(), rd, "123456", 443, 10, []deployment.IngressAnnotationProvider{}, []deployment.AuxiliaryResourceManager{})
_ = deployment.OnSync()
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.21
require (
github.com/equinor/radix-common v1.5.0
github.com/equinor/radix-job-scheduler v1.8.3
github.com/equinor/radix-operator v1.43.0
github.com/equinor/radix-operator v1.43.9
github.com/evanphx/json-patch/v5 v5.6.0
github.com/go-openapi/strfmt v0.21.7
github.com/golang-jwt/jwt/v4 v4.5.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ github.com/equinor/radix-common v1.5.0 h1:z5hQHlKG2x16/NnV4b9ynf9n5ZageYUewE4MAN
github.com/equinor/radix-common v1.5.0/go.mod h1:UZ69U56VFtTxABi5JjGdaqn9Df5ilfTTqzUQ0riofVM=
github.com/equinor/radix-job-scheduler v1.8.3 h1:SqxbLD3vfwQXlxr6U6R9odeonu5uTKLoBVv9P6Tqins=
github.com/equinor/radix-job-scheduler v1.8.3/go.mod h1:r71td0yDeDixdiMtq5TuCpCICD3lMHR8d1o5rSgTrTo=
github.com/equinor/radix-operator v1.43.0 h1:25vXiqy0BZrTu1VjA/kFgP7IGQ/UoFAtx0QCq0Irm8E=
github.com/equinor/radix-operator v1.43.0/go.mod h1:fa1yXgnhluKtqlBP+k/VldbkpFRpkK5eBGfGhuilqNc=
github.com/equinor/radix-operator v1.43.9 h1:+B6IqCgVFWOvvfiouNvBpNJ4yTvER2b60t0Mpvd1CAk=
github.com/equinor/radix-operator v1.43.9/go.mod h1:j/Lb9bcof4L+KjtHVv5GD6MqYVsxHSGsliIP6C2F8YU=
github.com/evanphx/json-patch v0.5.2/go.mod h1:ZWS5hhDbVDyob71nXKNL0+PWn6ToqBHMikGIFbs31qQ=
github.com/evanphx/json-patch v5.6.0+incompatible h1:jBYDEEiFBPxA0v50tFdvOzQQTCvpL6mnFh5mB2/l16U=
github.com/evanphx/json-patch v5.6.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk=
Expand Down
6 changes: 6 additions & 0 deletions swaggerui_src/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -6529,6 +6529,12 @@
"description": "PipelineParametersDeploy describes environment to deploy",
"type": "object",
"properties": {
"commitID": {
"description": "CommitID the commit ID of the branch\nOPTIONAL for information only",
"type": "string",
"x-go-name": "CommitID",
"example": "4faca8595c5283a9d0f17a623b9255a0d9866a2e"
},
"imageTagNames": {
"description": "Image tags names for components",
"type": "object",
Expand Down

0 comments on commit 954732f

Please sign in to comment.