Skip to content

Commit

Permalink
Merge pull request #977 from equinor/fix-build-deploy-hash-change-log…
Browse files Browse the repository at this point in the history
…ging

fix logging when build secret or radixconfig hash changed
  • Loading branch information
nilsgstrabo authored Nov 13, 2023
2 parents db87c36 + b8cb1d3 commit 87fd630
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 34 deletions.
4 changes: 2 additions & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"env": {},
"args": [
"--RADIX_APP=radix-job-demo",
"--JOB_NAME=radix-pipeline-20231030143058-mtwyg",
"--JOB_NAME=radix-pipeline-20231113133209-sb8w8",
"--PIPELINE_TYPE=build-deploy",
"--RADIX_TEKTON_IMAGE=radix-tekton:main-latest",
"--RADIX_IMAGE_BUILDER=radix-image-builder:master-latest",
Expand All @@ -23,7 +23,7 @@
"--AZURE_SUBSCRIPTION_ID=16ede44b-1f74-40a5-b428-46cca9a5741b",
"--IMAGE_TAG=abcde",
"--BRANCH=main",
"--COMMIT_ID=890e19c7bea84678d684daa2a9363cd8be4940bb",
"--COMMIT_ID=1cbb2fb6b8a562d44a27edae9678c86cb7cbda2e",
"--PUSH_IMAGE=true",
"--USE_CACHE=true",
"--RADIX_FILE_NAME=/workspace/radixconfig.yaml",
Expand Down
4 changes: 2 additions & 2 deletions charts/radix-operator/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
apiVersion: v2
name: radix-operator
version: 1.25.1
appVersion: 1.45.1
version: 1.25.2
appVersion: 1.45.2
kubeVersion: ">=1.24.0"
description: Radix Operator
keywords:
Expand Down
2 changes: 1 addition & 1 deletion pipeline-runner/model/pipelineInfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ func (info *PipelineInfo) SetApplicationConfig(applicationConfig *application.Ap
info.RadixApplication = applicationConfig.GetRadixApplicationConfig()

// Obtain metadata for rest of pipeline
targetEnvironments := applicationConfig.GetTargetEnvironments(info.PipelineArguments.Branch)
targetEnvironments := application.GetTargetEnvironments(info.PipelineArguments.Branch, info.RadixApplication)

// For deploy-only pipeline
if info.IsPipelineType(radixv1.Deploy) &&
Expand Down
4 changes: 2 additions & 2 deletions pipeline-runner/steps/apply_radixconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ func isRadixConfigNewOrModifiedSinceDeployment(rd *radixv1.RadixDeployment, ra *
return true, nil
}
hashEqual, err := compareRadixApplicationHash(currentRdConfigHash, ra)
if !hashEqual && err != nil {
if !hashEqual && err == nil {
log.Infof("RadixApplication updated since last deployment to environment %s", rd.Spec.Environment)
}
return !hashEqual, err
Expand All @@ -375,7 +375,7 @@ func isBuildSecretNewOrModifiedSinceDeployment(rd *radixv1.RadixDeployment, buil
return true, nil
}
hashEqual, err := compareBuildSecretHash(targetHash, buildSecret)
if !hashEqual && err != nil {
if !hashEqual && err == nil {
log.Infof("Build secrets updated since last deployment to environment %s", rd.Spec.Environment)
}
return !hashEqual, err
Expand Down
3 changes: 1 addition & 2 deletions pipeline-runner/steps/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,7 @@ func (s *buildTestSuite) Test_BranchIsNotMapped_ShouldSkip() {
cli := steps.NewBuildStep(jobWaiter)
cli.Init(s.kubeClient, s.radixClient, s.kubeUtil, s.promClient, rr)

applicationConfig := application.NewApplicationConfig(s.kubeClient, s.kubeUtil, s.radixClient, rr, ra)
targetEnvs := applicationConfig.GetTargetEnvironments(anyNoMappedBranch)
targetEnvs := application.GetTargetEnvironments(anyNoMappedBranch, ra)

pipelineInfo := &model.PipelineInfo{
PipelineArguments: model.PipelineArguments{
Expand Down
5 changes: 2 additions & 3 deletions pipeline-runner/steps/deploy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,7 @@ func TestDeploy_BranchIsNotMapped_ShouldSkip(t *testing.T) {
cli := steps.NewDeployStep(FakeNamespaceWatcher{})
cli.Init(kubeclient, radixclient, kubeUtil, &monitoring.Clientset{}, rr)

applicationConfig := application.NewApplicationConfig(kubeclient, kubeUtil, radixclient, rr, ra)
targetEnvs := applicationConfig.GetTargetEnvironments(anyNoMappedBranch)
targetEnvs := application.GetTargetEnvironments(anyNoMappedBranch, ra)

pipelineInfo := &model.PipelineInfo{
PipelineArguments: model.PipelineArguments{
Expand Down Expand Up @@ -181,7 +180,7 @@ func TestDeploy_PromotionSetup_ShouldCreateNamespacesForAllBranchesIfNotExists(t
cli.Init(kubeclient, radixclient, kubeUtil, &monitoring.Clientset{}, rr)

applicationConfig := application.NewApplicationConfig(kubeclient, kubeUtil, radixclient, rr, ra)
targetEnvs := applicationConfig.GetTargetEnvironments("master")
targetEnvs := application.GetTargetEnvironments("master", ra)

pipelineInfo := &model.PipelineInfo{
PipelineArguments: model.PipelineArguments{
Expand Down
4 changes: 2 additions & 2 deletions pkg/apis/applicationconfig/applicationconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,9 @@ func IsConfigBranch(branch string, rr *v1.RadixRegistration) bool {
}

// GetTargetEnvironments Checks if given branch requires deployment to environments
func (app *ApplicationConfig) GetTargetEnvironments(branchToBuild string) []string {
func GetTargetEnvironments(branchToBuild string, ra *v1.RadixApplication) []string {
var targetEnvs []string
for _, env := range app.config.Spec.Environments {
for _, env := range ra.Spec.Environments {
if env.Build.From != "" && branch.MatchesPattern(env.Build.From, branchToBuild) {
targetEnvs = append(targetEnvs, env.Name)
}
Expand Down
27 changes: 7 additions & 20 deletions pkg/apis/applicationconfig/applicationconfig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,6 @@ func setupTest() (*test.Utils, kubernetes.Interface, *kube.Kube, radixclient.Int
return &handlerTestUtils, kubeclient, kubeUtil, radixclient
}

func getApplication(ra *radixv1.RadixApplication) *ApplicationConfig {
// The other arguments are not relevant for this test
application := NewApplicationConfig(nil, nil, nil, nil, ra)
return application
}

func Test_Create_Radix_Environments(t *testing.T) {
_, client, kubeUtil, radixclient := setupTest()

Expand Down Expand Up @@ -136,8 +130,7 @@ func TestIsThereAnythingToDeploy_multipleEnvsToOneBranch_ListsBoth(t *testing.T)
WithEnvironment("prod", "master").
BuildRA()

application := getApplication(ra)
targetEnvs := application.GetTargetEnvironments(branch)
targetEnvs := GetTargetEnvironments(branch, ra)
assert.ElementsMatch(t, []string{"prod", "qa"}, targetEnvs)
}

Expand All @@ -149,8 +142,7 @@ func TestIsThereAnythingToDeploy_multipleEnvsToOneBranchOtherBranchIsChanged_Lis
WithEnvironment("prod", "master").
BuildRA()

application := getApplication(ra)
targetEnvs := application.GetTargetEnvironments(branch)
targetEnvs := GetTargetEnvironments(branch, ra)
assert.Equal(t, 0, len(targetEnvs))
}

Expand All @@ -162,8 +154,7 @@ func TestIsThereAnythingToDeploy_oneEnvToOneBranch_ListsBothButOnlyOneShouldBeBu
WithEnvironment("prod", "master").
BuildRA()

application := getApplication(ra)
targetEnvs := application.GetTargetEnvironments(branch)
targetEnvs := GetTargetEnvironments(branch, ra)
assert.ElementsMatch(t, []string{"qa"}, targetEnvs)
}

Expand All @@ -175,8 +166,7 @@ func TestIsThereAnythingToDeploy_twoEnvNoBranch(t *testing.T) {
WithEnvironmentNoBranch("prod").
BuildRA()

application := getApplication(ra)
targetEnvs := application.GetTargetEnvironments(branch)
targetEnvs := GetTargetEnvironments(branch, ra)
assert.Equal(t, 0, len(targetEnvs))
}

Expand All @@ -186,8 +176,7 @@ func TestIsThereAnythingToDeploy_NoEnv(t *testing.T) {
ra := utils.NewRadixApplicationBuilder().
BuildRA()

application := getApplication(ra)
targetEnvs := application.GetTargetEnvironments(branch)
targetEnvs := GetTargetEnvironments(branch, ra)
assert.Equal(t, 0, len(targetEnvs))
}

Expand All @@ -199,8 +188,7 @@ func TestIsThereAnythingToDeploy_promotionScheme_ListsBothButOnlyOneShouldBeBuil
WithEnvironment("prod", "").
BuildRA()

application := getApplication(ra)
targetEnvs := application.GetTargetEnvironments(branch)
targetEnvs := GetTargetEnvironments(branch, ra)
assert.ElementsMatch(t, []string{"qa"}, targetEnvs)
}

Expand All @@ -212,8 +200,7 @@ func TestIsThereAnythingToDeploy_wildcardMatch_ListsBothButOnlyOneShouldBeBuilt(
WithEnvironment("prod", "master").
BuildRA()

application := getApplication(ra)
targetEnvs := application.GetTargetEnvironments(branch)
targetEnvs := GetTargetEnvironments(branch, ra)
assert.ElementsMatch(t, []string{"feature"}, targetEnvs)
}

Expand Down

0 comments on commit 87fd630

Please sign in to comment.