Skip to content

Commit

Permalink
Merge pull request #1127 from equinor/master
Browse files Browse the repository at this point in the history
Release custom scaling triggers, ARM node affinity
  • Loading branch information
Richard87 authored Jun 5, 2024
2 parents 740b588 + 7ffd8b1 commit acedd17
Show file tree
Hide file tree
Showing 49 changed files with 2,732 additions and 958 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -172,4 +172,4 @@ ifndef HAS_MOCKGEN
endif
ifndef HAS_CONTROLLER_GEN
go install sigs.k8s.io/controller-tools/cmd/[email protected]
endif
endif
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.34.1
appVersion: 1.54.1
version: 1.35.2
appVersion: 1.55.2
kubeVersion: ">=1.24.0"
description: Radix Operator
keywords:
Expand Down
1 change: 1 addition & 0 deletions charts/radix-operator/templates/radix-operator-rbac.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ rules:
- keda.sh
resources:
- scaledobjects
- triggerauthentications
verbs:
- get
- list
Expand Down
367 changes: 361 additions & 6 deletions charts/radix-operator/templates/radixapplication.yaml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion charts/radix-operator/templates/radixdnsalias.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ spec:
properties:
appName:
description: Name of the application the DNS alias used in.
maxLength: 253
maxLength: 50
minLength: 1
pattern: ^(([a-z0-9][-a-z0-9]*)?[a-z0-9])?$
type: string
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ require (
github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring v0.70.0
github.com/prometheus-operator/prometheus-operator/pkg/client v0.70.0
github.com/prometheus/client_golang v1.19.0
github.com/robfig/cron/v3 v3.0.1
github.com/rs/zerolog v1.32.0
github.com/spf13/cobra v1.8.0
github.com/spf13/viper v1.18.2
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ github.com/prometheus/common v0.53.0 h1:U2pL9w9nmJwJDa4qqLQ3ZaePJ6ZTwt7cMD3AG3+a
github.com/prometheus/common v0.53.0/go.mod h1:BrxBKv3FWBIGXw89Mg1AeBq7FSyRzXWI3l3e7W3RN5U=
github.com/prometheus/procfs v0.12.0 h1:jluTpSng7V9hY0O2R9DzzJHYb2xULk9VTR1V1R/k6Bo=
github.com/prometheus/procfs v0.12.0/go.mod h1:pcuDEFsWDnvcgNzo4EEweacyhjeA9Zk3cnaOZAZEfOo=
github.com/robfig/cron/v3 v3.0.1 h1:WdRxkvbJztn8LMz/QEvLN5sBU+xKpSqwwUO1Pjr4qDs=
github.com/robfig/cron/v3 v3.0.1/go.mod h1:eQICP3HwyT7UooqI/z+Ov+PtYAWygg1TEWWzGIFLtro=
github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8=
github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4=
github.com/rs/xid v1.5.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg=
Expand Down
362 changes: 358 additions & 4 deletions json-schema/radixapplication.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pipeline-runner/internal/tekton/tekton.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func CreateActionPipelineJob(containerName string, action string, pipelineInfo *
},
Volumes: getJobVolumes(),
RestartPolicy: "Never",
Affinity: utils.GetPipelineJobPodSpecAffinity(),
Affinity: utils.GetAffinityForPipelineJob(),
Tolerations: utils.GetPipelineJobPodSpecTolerations(),
},
},
Expand Down
2 changes: 1 addition & 1 deletion pipeline-runner/steps/build_acr.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func buildContainerImageBuildingJob(rr *v1.RadixRegistration, pipelineInfo *mode
Containers: buildContainers,
SecurityContext: buildPodSecurityContext,
Volumes: getContainerImageBuildingJobVolumes(&defaultMode, buildSecrets, isUsingBuildKit(pipelineInfo), buildContainers),
Affinity: utils.GetPipelineJobPodSpecAffinity(),
Affinity: utils.GetAffinityForPipelineJob(),
Tolerations: utils.GetPipelineJobPodSpecTolerations(),
},
},
Expand Down
12 changes: 12 additions & 0 deletions pipeline-runner/steps/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,12 @@ func (s *buildTestSuite) Test_BuildDeploy_JobSpecAndDeploymentConsistent() {
{Name: "var-build-c1-dev", VolumeSource: corev1.VolumeSource{EmptyDir: &corev1.EmptyDirVolumeSource{SizeLimit: resource.NewScaledQuantity(100, resource.Giga)}}},
}
s.ElementsMatch(expectedVolumes, job.Spec.Template.Spec.Volumes)
expectedAffinity := &corev1.Affinity{NodeAffinity: &corev1.NodeAffinity{RequiredDuringSchedulingIgnoredDuringExecution: &corev1.NodeSelector{NodeSelectorTerms: []corev1.NodeSelectorTerm{{MatchExpressions: []corev1.NodeSelectorRequirement{
{Key: kube.RadixJobNodeLabel, Operator: corev1.NodeSelectorOpExists},
{Key: corev1.LabelOSStable, Operator: corev1.NodeSelectorOpIn, Values: []string{defaults.DefaultNodeSelectorOS}},
{Key: corev1.LabelArchStable, Operator: corev1.NodeSelectorOpIn, Values: []string{defaults.DefaultNodeSelectorArchitecture}},
}}}}}}
s.Equal(expectedAffinity, job.Spec.Template.Spec.Affinity)

// Check init containers
s.Len(job.Spec.Template.Spec.InitContainers, 2)
Expand Down Expand Up @@ -1469,6 +1475,12 @@ func (s *buildTestSuite) Test_BuildJobSpec_BuildKit() {
{Name: "var-build-c1-dev", MountPath: "/var", ReadOnly: false},
}
s.ElementsMatch(job.Spec.Template.Spec.Containers[0].VolumeMounts, expectedVolumeMounts)
expectedAffinity := &corev1.Affinity{NodeAffinity: &corev1.NodeAffinity{RequiredDuringSchedulingIgnoredDuringExecution: &corev1.NodeSelector{NodeSelectorTerms: []corev1.NodeSelectorTerm{{MatchExpressions: []corev1.NodeSelectorRequirement{
{Key: kube.RadixJobNodeLabel, Operator: corev1.NodeSelectorOpExists},
{Key: corev1.LabelOSStable, Operator: corev1.NodeSelectorOpIn, Values: []string{defaults.DefaultNodeSelectorOS}},
{Key: corev1.LabelArchStable, Operator: corev1.NodeSelectorOpIn, Values: []string{defaults.DefaultNodeSelectorArchitecture}},
}}}}}}
s.Equal(expectedAffinity, job.Spec.Template.Spec.Affinity)
}

func (s *buildTestSuite) Test_BuildJobSpec_BuildKit_PushImage() {
Expand Down
2 changes: 1 addition & 1 deletion pkg/apis/batch/kubejob.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ func (s *syncer) buildJob(ctx context.Context, batchJob *radixv1.RadixBatchJob,
SecurityContext: securitycontext.Pod(securitycontext.WithPodSeccompProfile(corev1.SeccompProfileTypeRuntimeDefault)),
RestartPolicy: corev1.RestartPolicyNever,
ImagePullSecrets: rd.Spec.ImagePullSecrets,
Affinity: operatorUtils.GetScheduledJobPodSpecAffinity(node),
Affinity: operatorUtils.GetAffinityForBatchJob(node),
Tolerations: operatorUtils.GetScheduledJobPodSpecTolerations(node),
ActiveDeadlineSeconds: timeLimitSeconds,
ServiceAccountName: serviceAccountSpec.ServiceAccountName(),
Expand Down
18 changes: 8 additions & 10 deletions pkg/apis/batch/syncer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -517,17 +517,15 @@ func (s *syncerTestSuite) Test_BatchStaticConfiguration() {
s.Equal(corev1.PullAlways, kubejob.Spec.Template.Spec.Containers[0].ImagePullPolicy)
s.Equal("default", kubejob.Spec.Template.Spec.ServiceAccountName)
s.Equal(utils.BoolPtr(false), kubejob.Spec.Template.Spec.AutomountServiceAccountToken)
s.Require().Len(kubejob.Spec.Template.Spec.Affinity.NodeAffinity.RequiredDuringSchedulingIgnoredDuringExecution.NodeSelectorTerms, 1)
s.Equal(corev1.NodeSelectorRequirement{
Key: kube.RadixJobNodeLabel,
Operator: corev1.NodeSelectorOpExists,
}, kubejob.Spec.Template.Spec.Affinity.NodeAffinity.RequiredDuringSchedulingIgnoredDuringExecution.NodeSelectorTerms[0].MatchExpressions[0])
expectedAffinity := &corev1.Affinity{NodeAffinity: &corev1.NodeAffinity{RequiredDuringSchedulingIgnoredDuringExecution: &corev1.NodeSelector{NodeSelectorTerms: []corev1.NodeSelectorTerm{{MatchExpressions: []corev1.NodeSelectorRequirement{
{Key: kube.RadixJobNodeLabel, Operator: corev1.NodeSelectorOpExists},
{Key: corev1.LabelOSStable, Operator: corev1.NodeSelectorOpIn, Values: []string{defaults.DefaultNodeSelectorOS}},
{Key: corev1.LabelArchStable, Operator: corev1.NodeSelectorOpIn, Values: []string{defaults.DefaultNodeSelectorArchitecture}},
}}}}}}
s.Equal(expectedAffinity, kubejob.Spec.Template.Spec.Affinity)
s.Len(kubejob.Spec.Template.Spec.Tolerations, 1)
s.Equal(corev1.Toleration{
Key: kube.NodeTaintJobsKey,
Operator: corev1.TolerationOpExists,
Effect: corev1.TaintEffectNoSchedule,
}, kubejob.Spec.Template.Spec.Tolerations[0])
expectedTolerations := []corev1.Toleration{{Key: kube.NodeTaintJobsKey, Operator: corev1.TolerationOpExists, Effect: corev1.TaintEffectNoSchedule}}
s.ElementsMatch(expectedTolerations, kubejob.Spec.Template.Spec.Tolerations)
s.Len(kubejob.Spec.Template.Spec.Volumes, 0)
s.Len(kubejob.Spec.Template.Spec.Containers[0].VolumeMounts, 0)
services, err := s.kubeClient.CoreV1().Services(namespace).List(context.Background(), metav1.ListOptions{})
Expand Down
6 changes: 6 additions & 0 deletions pkg/apis/defaults/pod.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package defaults

const (
DefaultNodeSelectorArchitecture = "amd64"
DefaultNodeSelectorOS = "linux"
)
8 changes: 8 additions & 0 deletions pkg/apis/deployment/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/equinor/radix-operator/pkg/apis/kube"
"github.com/equinor/radix-operator/pkg/apis/metrics"
v1 "github.com/equinor/radix-operator/pkg/apis/radix/v1"
"github.com/equinor/radix-operator/pkg/apis/utils"
radixclient "github.com/equinor/radix-operator/pkg/client/clientset/versioned"
monitoring "github.com/prometheus-operator/prometheus-operator/pkg/client/versioned"
"github.com/rs/zerolog/log"
Expand Down Expand Up @@ -401,6 +402,11 @@ func (deploy *Deployment) garbageCollectComponentsNoLongerInSpec(ctx context.Con
return err
}

err = deploy.garbageCollectTriggerAuthsNoLongerInSpec(ctx)
if err != nil {
return err
}

err = deploy.garbageCollectServicesNoLongerInSpec(ctx)
if err != nil {
return err
Expand Down Expand Up @@ -602,12 +608,14 @@ func (deploy *Deployment) createOrUpdateJobAuxDeployment(ctx context.Context, de
desiredJobAuxDeployment.ObjectMeta.Labels = deploy.getJobAuxDeploymentLabels(deployComponent)
desiredJobAuxDeployment.Spec.Template.Labels = deploy.getJobAuxDeploymentPodLabels(deployComponent)
desiredJobAuxDeployment.Spec.Template.Spec.ServiceAccountName = (&radixComponentServiceAccountSpec{component: deployComponent}).ServiceAccountName()
desiredJobAuxDeployment.Spec.Template.Spec.Affinity = utils.GetAffinityForJobAPIAuxComponent()
// Copy volumes and volume mounts from desired deployment to job aux deployment
desiredJobAuxDeployment.Spec.Template.Spec.Volumes = desiredDeployment.Spec.Template.Spec.Volumes
desiredJobAuxDeployment.Spec.Template.Spec.Containers[0].VolumeMounts = desiredDeployment.Spec.Template.Spec.Containers[0].VolumeMounts
// Remove volumes and volume mounts from job scheduler deployment
desiredDeployment.Spec.Template.Spec.Volumes = nil
desiredDeployment.Spec.Template.Spec.Containers[0].VolumeMounts = nil

syncRadixRestartEnvironmentVariable(deployComponent, desiredJobAuxDeployment)
return currentJobAuxDeployment, desiredJobAuxDeployment, nil
}
Expand Down
Loading

0 comments on commit acedd17

Please sign in to comment.