Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

apply-config-job #1087

Merged
merged 6 commits into from
Apr 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.31.2
appVersion: 1.51.1
version: 1.31.3
appVersion: 1.51.2
kubeVersion: ">=1.24.0"
description: Radix Operator
keywords:
Expand Down
11 changes: 11 additions & 0 deletions pipeline-runner/model/pipelineInfo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,17 @@ func Test_BuildAndDefaultNoPushOnlyPipeline(t *testing.T) {
assert.Equal(t, "run pipelines completed", p.Steps[3].SucceededMsg())
}

func Test_ApplyConfigPipeline(t *testing.T) {
pipelineType, _ := pipeline.GetPipelineFromName(string(v1.ApplyConfig))

p, _ := model.InitPipeline(pipelineType, getPipelineArguments(), prepareTektonPipelineStep, applyConfigStep)
assert.Equal(t, v1.ApplyConfig, p.Definition.Type)
assert.False(t, p.PipelineArguments.PushImage)
assert.Equal(t, 2, len(p.Steps))
assert.Equal(t, "pipelines prepared", p.Steps[0].SucceededMsg())
assert.Equal(t, "config applied", p.Steps[1].SucceededMsg())
}

func Test_GetImageTagNamesFromArgs(t *testing.T) {
pipelineType, _ := pipeline.GetPipelineFromName(string(v1.Deploy))
type scenario struct {
Expand Down
44 changes: 44 additions & 0 deletions pipeline-runner/steps/apply_radixconfig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,50 @@ func (s *applyConfigTestSuite) Test_Deploy_BuildJobInDeployPiplineShouldFail() {
s.ErrorIs(err, steps.ErrDeployOnlyPipelineDoesNotSupportBuild)
}

func (s *applyConfigTestSuite) Test_ApplyConfig_ShouldNotFail() {
appName := "anyapp"
prepareConfigMapName := "preparecm"
type scenario struct {
name string
componentBuilder *utils.RadixApplicationComponentBuilder
jobComponentBuilder *utils.RadixApplicationJobComponentBuilder
}
scenarios := []scenario{
{name: "no components"},
{name: "with a component", componentBuilder: pointers.Ptr(utils.NewApplicationComponentBuilder().WithPort("any", 8080).WithName("comp1"))},
{name: "with a job-component", jobComponentBuilder: pointers.Ptr(utils.NewApplicationJobComponentBuilder().WithSchedulerPort(pointers.Ptr[int32](8080)).WithName("job1"))},
}

for _, ts := range scenarios {
s.T().Run(ts.name, func(t *testing.T) {
s.SetupTest()
rr := utils.NewRegistrationBuilder().WithName(appName).BuildRR()
_, _ = s.radixClient.RadixV1().RadixRegistrations().Create(context.Background(), rr, metav1.CreateOptions{})
raBuilder := utils.NewRadixApplicationBuilder().
WithAppName(appName).
WithEnvironment("dev", "anybranch")
if ts.componentBuilder != nil {
raBuilder = raBuilder.WithComponent(*ts.componentBuilder)
}
if ts.jobComponentBuilder != nil {
raBuilder = raBuilder.WithJobComponent(*ts.jobComponentBuilder)
}
ra := raBuilder.BuildRA()
s.Require().NoError(internaltest.CreatePreparePipelineConfigMapResponse(s.kubeClient, prepareConfigMapName, appName, ra, nil))

pipeline := model.PipelineInfo{
PipelineArguments: model.PipelineArguments{},
RadixConfigMapName: prepareConfigMapName,
}

applyStep := steps.NewApplyConfigStep()
applyStep.Init(s.kubeClient, s.radixClient, s.kubeUtil, s.promClient, rr)
err := applyStep.Run(&pipeline)
s.NoError(err)
})
}
}

func (s *applyConfigTestSuite) Test_Deploy_ComponentImageTagName() {
appName := "anyapp"
prepareConfigMapName := "preparecm"
Expand Down
14 changes: 13 additions & 1 deletion pipeline-runner/steps/prepare_pipelines.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func (cli *PreparePipelinesStepImplementation) Run(pipelineInfo *model.PipelineI
commitID := pipelineInfo.PipelineArguments.CommitID
appName := cli.GetAppName()
namespace := utils.GetAppNamespace(appName)
log.Info().Msgf("Prepare pipelines app %s for branch %s and commit %s", appName, branch, commitID)
logPipelineInfo(pipelineInfo.Definition.Type, appName, branch, commitID)

if pipelineInfo.IsPipelineType(radixv1.Promote) {
sourceDeploymentGitCommitHash, sourceDeploymentGitBranch, err := cli.getSourceDeploymentGitInfo(appName, pipelineInfo.PipelineArguments.FromEnvironment, pipelineInfo.PipelineArguments.DeploymentName)
Expand Down Expand Up @@ -102,6 +102,18 @@ func (cli *PreparePipelinesStepImplementation) Run(pipelineInfo *model.PipelineI
return cli.jobWaiter.Wait(job)
}

func logPipelineInfo(pipelineType radixv1.RadixPipelineType, appName, branch, commitID string) {
stringBuilder := strings.Builder{}
stringBuilder.WriteString(fmt.Sprintf("Prepare pipeline %s for the app %s", pipelineType, appName))
if len(branch) > 0 {
stringBuilder.WriteString(fmt.Sprintf(", the branch %s", branch))
}
if len(branch) > 0 {
stringBuilder.WriteString(fmt.Sprintf(", the commit %s", commitID))
}
log.Info().Msg(stringBuilder.String())
}

func (cli *PreparePipelinesStepImplementation) getPreparePipelinesJobConfig(pipelineInfo *model.PipelineInfo) *batchv1.Job {
appName := cli.GetAppName()
registration := cli.GetRegistration()
Expand Down
2 changes: 1 addition & 1 deletion pkg/apis/job/job_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,12 +222,12 @@ func (s *RadixJobTestSuite) TestObjectSynced_PipelineJobCreated() {
fmt.Sprintf("--AZURE_SUBSCRIPTION_ID=%s", s.config.subscriptionID),
"--RADIX_RESERVED_APP_DNS_ALIASES=api=radix-api",
"--RADIX_RESERVED_DNS_ALIASES=grafana",
"--RADIX_FILE_NAME=/workspace/radixconfig.yaml",
fmt.Sprintf("--IMAGE_TAG=%s", imageTag),
fmt.Sprintf("--BRANCH=%s", branch),
fmt.Sprintf("--COMMIT_ID=%s", commitID),
"--PUSH_IMAGE=1",
"--USE_CACHE=",
"--RADIX_FILE_NAME=/workspace/radixconfig.yaml",
},
SecurityContext: &corev1.SecurityContext{
Privileged: pointers.Ptr(false),
Expand Down
12 changes: 5 additions & 7 deletions pkg/apis/job/kubejob.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,10 @@ func (job *Job) getPipelineJobArguments(appName, jobName string, jobSpec v1.Radi
if job.radixJob.Spec.TektonImage != "" {
radixTektonImage = fmt.Sprintf("%s:%s", tektonImage, job.radixJob.Spec.TektonImage)
}
radixConfigFullName := jobSpec.RadixConfigFullName
if len(radixConfigFullName) == 0 {
radixConfigFullName = fmt.Sprintf("%s/%s", git.Workspace, defaults.DefaultRadixConfigFileName)
}

// Base arguments for all types of pipeline
args := []string{
Expand All @@ -175,32 +179,26 @@ func (job *Job) getPipelineJobArguments(appName, jobName string, jobSpec v1.Radi
fmt.Sprintf("--%s=%s", defaults.AzureSubscriptionIdEnvironmentVariable, subscriptionId),
fmt.Sprintf("--%s=%s", defaults.RadixReservedAppDNSAliasesEnvironmentVariable, maps.ToString(job.config.DNSConfig.ReservedAppDNSAliases)),
fmt.Sprintf("--%s=%s", defaults.RadixReservedDNSAliasesEnvironmentVariable, strings.Join(job.config.DNSConfig.ReservedDNSAliases, ",")),
fmt.Sprintf("--%s=%s", defaults.RadixConfigFileEnvironmentVariable, radixConfigFullName),
}

radixConfigFullName := jobSpec.RadixConfigFullName
if len(radixConfigFullName) == 0 {
radixConfigFullName = fmt.Sprintf("%s/%s", git.Workspace, defaults.DefaultRadixConfigFileName)
}
switch pipeline.Type {
case v1.BuildDeploy, v1.Build:
args = append(args, fmt.Sprintf("--%s=%s", defaults.RadixImageTagEnvironmentVariable, jobSpec.Build.ImageTag))
args = append(args, fmt.Sprintf("--%s=%s", defaults.RadixBranchEnvironmentVariable, jobSpec.Build.Branch))
args = append(args, fmt.Sprintf("--%s=%s", defaults.RadixCommitIdEnvironmentVariable, jobSpec.Build.CommitID))
args = append(args, fmt.Sprintf("--%s=%s", defaults.RadixPushImageEnvironmentVariable, getPushImageTag(jobSpec.Build.PushImage)))
args = append(args, fmt.Sprintf("--%s=%s", defaults.RadixUseCacheEnvironmentVariable, useImageBuilderCache))
args = append(args, fmt.Sprintf("--%s=%s", defaults.RadixConfigFileEnvironmentVariable, radixConfigFullName))
case v1.Promote:
args = append(args, fmt.Sprintf("--%s=%s", defaults.RadixPromoteDeploymentEnvironmentVariable, jobSpec.Promote.DeploymentName))
args = append(args, fmt.Sprintf("--%s=%s", defaults.RadixPromoteFromEnvironmentEnvironmentVariable, jobSpec.Promote.FromEnvironment))
args = append(args, fmt.Sprintf("--%s=%s", defaults.RadixPromoteToEnvironmentEnvironmentVariable, jobSpec.Promote.ToEnvironment))
args = append(args, fmt.Sprintf("--%s=%s", defaults.RadixConfigFileEnvironmentVariable, radixConfigFullName))
case v1.Deploy:
args = append(args, fmt.Sprintf("--%s=%s", defaults.RadixPromoteToEnvironmentEnvironmentVariable, jobSpec.Deploy.ToEnvironment))
args = append(args, fmt.Sprintf("--%s=%s", defaults.RadixCommitIdEnvironmentVariable, jobSpec.Deploy.CommitID))
for componentName, imageTagName := range jobSpec.Deploy.ImageTagNames {
args = append(args, fmt.Sprintf("--%s=%s=%s", defaults.RadixImageTagNameEnvironmentVariable, componentName, imageTagName))
}
args = append(args, fmt.Sprintf("--%s=%s", defaults.RadixConfigFileEnvironmentVariable, radixConfigFullName))
args = append(args, fmt.Sprintf("--%s=%s", defaults.RadixComponentsToDeployVariable, strings.Join(jobSpec.Deploy.ComponentsToDeploy, ",")))
}

Expand Down
6 changes: 5 additions & 1 deletion pkg/apis/pipeline/pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,11 @@ func GetSupportedPipelines() []Definition {
PreparePipelinesStep,
ApplyConfigStep,
RunPipelinesStep,
DeployStep}}}
DeployStep}},
{v1.ApplyConfig, []StepType{
PreparePipelinesStep,
ApplyConfigStep}},
}
}

// GetPipelineFromName Gets pipeline from string
Expand Down
4 changes: 4 additions & 0 deletions pkg/apis/pipeline/pipeline_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,8 @@ func Test_StringToPipelineToString(t *testing.T) {
p, _ = GetPipelineFromName("build")

assert.Equal(t, "build", string(p.Type))

p, _ = GetPipelineFromName("apply-config")

assert.Equal(t, "apply-config", string(p.Type))
}
1 change: 1 addition & 0 deletions pkg/apis/radix/v1/radixjobtypes.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ const (
BuildDeploy RadixPipelineType = "build-deploy"
Promote RadixPipelineType = "promote"
Deploy RadixPipelineType = "deploy"
ApplyConfig RadixPipelineType = "apply-config"
)

// RadixBuildSpec is the spec for a build job
Expand Down