Skip to content

Commit

Permalink
Merge pull request #956 from equinor/master
Browse files Browse the repository at this point in the history
Release radix-operator
  • Loading branch information
nilsgstrabo authored Oct 18, 2023
2 parents 5741da0 + 7c9e546 commit cea8f4b
Show file tree
Hide file tree
Showing 17 changed files with 347 additions and 78 deletions.
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.23.7
appVersion: 1.43.7
version: 1.23.9
appVersion: 1.43.9
kubeVersion: ">=1.24.0"
description: Radix Operator
keywords:
Expand Down
5 changes: 2 additions & 3 deletions pipeline-runner/steps/build_acr.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/equinor/radix-operator/pkg/apis/utils"
radixannotations "github.com/equinor/radix-operator/pkg/apis/utils/annotations"
"github.com/equinor/radix-operator/pkg/apis/utils/git"
radixlabels "github.com/equinor/radix-operator/pkg/apis/utils/labels"
batchv1 "k8s.io/api/batch/v1"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
Expand Down Expand Up @@ -67,9 +68,7 @@ func createACRBuildJob(rr *v1.RadixRegistration, pipelineInfo *model.PipelineInf
BackoffLimit: &backOffLimit,
Template: corev1.PodTemplateSpec{
ObjectMeta: metav1.ObjectMeta{
Labels: map[string]string{
kube.RadixJobNameLabel: jobName,
},
Labels: radixlabels.ForPipelineJobName(jobName),
Annotations: annotations,
},
Spec: corev1.PodSpec{
Expand Down
3 changes: 2 additions & 1 deletion pipeline-runner/steps/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
radix "github.com/equinor/radix-operator/pkg/client/clientset/versioned/fake"
monitoring "github.com/prometheus-operator/prometheus-operator/pkg/client/versioned"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
kubernetes "k8s.io/client-go/kubernetes/fake"
secretproviderfake "sigs.k8s.io/secrets-store-csi-driver/pkg/client/clientset/versioned/fake"
Expand Down Expand Up @@ -68,7 +69,7 @@ func TestBuild_BranchIsNotMapped_ShouldSkip(t *testing.T) {
}

err := cli.Run(pipelineInfo)
assert.NoError(t, err)
require.NoError(t, err)
radixJobList, err := radixclient.RadixV1().RadixJobs(utils.GetAppNamespace(anyAppName)).List(context.Background(), metav1.ListOptions{})
assert.NoError(t, err)
assert.Empty(t, radixJobList.Items)
Expand Down
9 changes: 6 additions & 3 deletions pipeline-runner/steps/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/equinor/radix-operator/pkg/apis/deployment"
"github.com/equinor/radix-operator/pkg/apis/kube"
"github.com/equinor/radix-operator/pkg/apis/pipeline"
v1 "github.com/equinor/radix-operator/pkg/apis/radix/v1"
radixv1 "github.com/equinor/radix-operator/pkg/apis/radix/v1"
"github.com/equinor/radix-operator/pkg/apis/utils"
log "github.com/sirupsen/logrus"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -82,6 +82,9 @@ func (cli *DeployStepImplementation) deployToEnv(appName, env string, pipelineIn
return fmt.Errorf("failed to retrieve default env vars for RadixDeployment in app %s. %v", appName, err)
}

if commitID, ok := defaultEnvVars[defaults.RadixCommitHashEnvironmentVariable]; !ok || len(commitID) == 0 {
defaultEnvVars[defaults.RadixCommitHashEnvironmentVariable] = pipelineInfo.PipelineArguments.CommitID // Commit ID specified by job arguments
}
radixDeployment, err := deployment.ConstructForTargetEnvironment(
pipelineInfo.RadixApplication,
pipelineInfo.PipelineArguments.JobName,
Expand Down Expand Up @@ -109,11 +112,11 @@ func (cli *DeployStepImplementation) deployToEnv(appName, env string, pipelineIn
return nil
}

func getDefaultEnvVars(pipelineInfo *model.PipelineInfo) (v1.EnvVarsMap, error) {
func getDefaultEnvVars(pipelineInfo *model.PipelineInfo) (radixv1.EnvVarsMap, error) {
gitCommitHash := pipelineInfo.GitCommitHash
gitTags := pipelineInfo.GitTags

envVarsMap := make(v1.EnvVarsMap)
envVarsMap := make(radixv1.EnvVarsMap)
envVarsMap[defaults.RadixCommitHashEnvironmentVariable] = gitCommitHash
envVarsMap[defaults.RadixGitTagsEnvironmentVariable] = gitTags

Expand Down
64 changes: 57 additions & 7 deletions pipeline-runner/steps/deploy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"testing"

"github.com/equinor/radix-operator/pkg/apis/defaults"
"github.com/stretchr/testify/require"

"github.com/equinor/radix-operator/pipeline-runner/model"
application "github.com/equinor/radix-operator/pkg/apis/applicationconfig"
Expand All @@ -19,12 +20,11 @@ import (
)

const (
anyContainerRegistry = "any.container.registry"
anyAppName = "any-app"
anyJobName = "any-job-name"
anyImageTag = "anytag"
anyCommitID = "4faca8595c5283a9d0f17a623b9255a0d9866a2e"
anyGitTags = "some tags go here"
anyAppName = "any-app"
anyJobName = "any-job-name"
anyImageTag = "anytag"
anyCommitID = "4faca8595c5283a9d0f17a623b9255a0d9866a2e"
anyGitTags = "some tags go here"
)

// FakeNamespaceWatcher Unit tests doesn't handle muliti-threading well
Expand Down Expand Up @@ -74,7 +74,7 @@ func TestDeploy_BranchIsNotMapped_ShouldSkip(t *testing.T) {
}

err := cli.Run(pipelineInfo)
assert.NoError(t, err)
require.NoError(t, err)
radixJobList, err := radixclient.RadixV1().RadixJobs(utils.GetAppNamespace(anyAppName)).List(context.Background(), metav1.ListOptions{})
assert.NoError(t, err)
assert.Empty(t, radixJobList.Items)
Expand Down Expand Up @@ -187,6 +187,7 @@ func TestDeploy_PromotionSetup_ShouldCreateNamespacesForAllBranchesIfNotExists(t
pipelineInfo.SetApplicationConfig(applicationConfig)
pipelineInfo.SetGitAttributes(gitCommitHash, gitTags)
err := cli.Run(pipelineInfo)
require.NoError(t, err)
rds, _ := radixclient.RadixV1().RadixDeployments("any-app-dev").List(context.TODO(), metav1.ListOptions{})

t.Run("validate deploy", func(t *testing.T) {
Expand Down Expand Up @@ -262,3 +263,52 @@ func TestDeploy_PromotionSetup_ShouldCreateNamespacesForAllBranchesIfNotExists(t
})

}

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

rr := utils.ARadixRegistration().
WithName(anyAppName).
BuildRR()

ra := utils.NewRadixApplicationBuilder().
WithAppName(anyAppName).
WithEnvironment("dev", "master").
WithComponents(utils.AnApplicationComponent().WithName("app")).
BuildRA()

// Prometheus doesn´t contain any fake
cli := NewDeployStep(FakeNamespaceWatcher{})
cli.Init(kubeclient, radixclient, kubeUtil, &monitoring.Clientset{}, rr)

applicationConfig, _ := application.NewApplicationConfig(kubeclient, kubeUtil, radixclient, rr, ra)

const commitID = "222ca8595c5283a9d0f17a623b9255a0d9866a2e"

pipelineInfo := &model.PipelineInfo{
PipelineArguments: model.PipelineArguments{
JobName: anyJobName,
ImageTag: anyImageTag,
Branch: "master",
CommitID: anyCommitID,
},
BranchIsMapped: true,
TargetEnvironments: map[string]bool{"master": true},
GitCommitHash: commitID,
GitTags: "",
}

gitCommitHash := pipelineInfo.GitCommitHash
gitTags := pipelineInfo.GitTags

pipelineInfo.SetApplicationConfig(applicationConfig)
pipelineInfo.SetGitAttributes(gitCommitHash, gitTags)
err := cli.Run(pipelineInfo)
require.NoError(t, err)
rds, err := radixclient.RadixV1().RadixDeployments("any-app-dev").List(context.TODO(), metav1.ListOptions{})

assert.NoError(t, err)
require.Len(t, rds.Items, 1)
rd := rds.Items[0]
assert.Equal(t, commitID, rd.ObjectMeta.Labels[kube.RadixCommitLabel])
}
15 changes: 11 additions & 4 deletions pipeline-runner/steps/prepare_pipelines.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ package steps
import (
"context"
"fmt"
"github.com/equinor/radix-operator/pkg/apis/kube"
v1 "github.com/equinor/radix-operator/pkg/apis/radix/v1"

"github.com/equinor/radix-operator/pipeline-runner/model"
pipelineDefaults "github.com/equinor/radix-operator/pipeline-runner/model/defaults"
pipelineUtils "github.com/equinor/radix-operator/pipeline-runner/utils"
"github.com/equinor/radix-operator/pkg/apis/applicationconfig"
"github.com/equinor/radix-operator/pkg/apis/defaults"
jobUtil "github.com/equinor/radix-operator/pkg/apis/job"
"github.com/equinor/radix-operator/pkg/apis/kube"
"github.com/equinor/radix-operator/pkg/apis/pipeline"
radixv1 "github.com/equinor/radix-operator/pkg/apis/radix/v1"
"github.com/equinor/radix-operator/pkg/apis/utils"
"github.com/equinor/radix-operator/pkg/apis/utils/git"
log "github.com/sirupsen/logrus"
Expand Down Expand Up @@ -57,7 +57,7 @@ func (cli *PreparePipelinesStepImplementation) Run(pipelineInfo *model.PipelineI
namespace := utils.GetAppNamespace(appName)
log.Infof("Prepare pipelines app %s for branch %s and commit %s", appName, branch, commitID)

if v1.RadixPipelineType(pipelineInfo.PipelineArguments.PipelineType) == v1.Promote {
if radixv1.RadixPipelineType(pipelineInfo.PipelineArguments.PipelineType) == radixv1.Promote {
sourceDeploymentGitCommitHash, sourceDeploymentGitBranch, err := cli.getSourceDeploymentGitInfo(appName, pipelineInfo.PipelineArguments.FromEnvironment, pipelineInfo.PipelineArguments.DeploymentName)
if err != nil {
return err
Expand Down Expand Up @@ -159,7 +159,7 @@ func (cli *PreparePipelinesStepImplementation) getPreparePipelinesJobConfig(pipe
},
{
Name: defaults.RadixGithubWebhookCommitId,
Value: pipelineInfo.PipelineArguments.CommitID,
Value: getWebhookCommitID(pipelineInfo),
},
}
sshURL := registration.Spec.CloneURL
Expand All @@ -169,6 +169,13 @@ func (cli *PreparePipelinesStepImplementation) getPreparePipelinesJobConfig(pipe

}

func getWebhookCommitID(pipelineInfo *model.PipelineInfo) string {
if pipelineInfo.PipelineArguments.PipelineType == string(radixv1.BuildDeploy) {
return pipelineInfo.PipelineArguments.CommitID
}
return ""
}

func (cli *PreparePipelinesStepImplementation) getInitContainerCloningRepo(pipelineInfo *model.PipelineInfo, configBranch, sshURL string) []corev1.Container {
return git.CloneInitContainersWithContainerName(sshURL, configBranch, git.CloneConfigContainerName,
pipelineInfo.PipelineArguments.ContainerSecurityContext)
Expand Down
5 changes: 5 additions & 0 deletions pipeline-runner/steps/promotion.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,15 @@ func (cli *PromoteStepImplementation) Run(pipelineInfo *model.PipelineInfo) erro
radixDeployment = rd.DeepCopy()
radixDeployment.Name = utils.GetDeploymentName(cli.GetAppName(), pipelineInfo.PipelineArguments.ToEnvironment, pipelineInfo.PipelineArguments.ImageTag)

if radixDeployment.GetAnnotations() == nil {
radixDeployment.ObjectMeta.Annotations = make(map[string]string)
}
if _, isRestored := radixDeployment.Annotations[kube.RestoredStatusAnnotation]; isRestored {
// RA-817: Promotion reuses annotation - RD get inactive status
radixDeployment.Annotations[kube.RestoredStatusAnnotation] = ""
}
radixDeployment.Annotations[kube.RadixDeploymentPromotedFromDeploymentAnnotation] = rd.GetName()
radixDeployment.Annotations[kube.RadixDeploymentPromotedFromEnvironmentAnnotation] = pipelineInfo.PipelineArguments.FromEnvironment

radixDeployment.ResourceVersion = ""
radixDeployment.Namespace = toNs
Expand Down
Loading

0 comments on commit cea8f4b

Please sign in to comment.