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

Refactor volume mount logic #1264

Merged
merged 89 commits into from
Feb 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
89 commits
Select commit Hold shift + click to select a range
27f0b32
Replacing the storage class with pv
satr Nov 12, 2024
9c9d98f
Replacing the storage class with pv
satr Nov 13, 2024
6bf84c4
Added blobfuse properties
satr Nov 13, 2024
2a0e905
Added blobfuse properties
satr Nov 13, 2024
9ba8425
Added blobfuse properties
satr Nov 15, 2024
8fbc630
Merge remote-tracking branch 'origin/master' into refactor-volume-mou…
satr Nov 25, 2024
2ccb43f
Added blobfuse properties
satr Nov 25, 2024
98dde7c
Added blobfuse properties
satr Nov 26, 2024
9df11d0
Added blobfuse properties
satr Nov 27, 2024
e6acdf3
Removed support for deprecated volume mount blob. Changing logic to c…
satr Dec 2, 2024
f2545e0
Changing logic to create pvc and pv
satr Dec 3, 2024
cf9199a
Fixed unit test, regenerated types
satr Dec 4, 2024
426939b
Correcting pv, pvc logic and tests
satr Dec 5, 2024
39d48ed
Correcting unit-tests
satr Dec 6, 2024
49390b8
Correcting unit-tests
satr Dec 6, 2024
51a9f06
Correcting unit-tests
satr Dec 6, 2024
38ee3f4
Correcting unit-tests
satr Dec 9, 2024
cb6f145
Correcting unit-tests
satr Dec 9, 2024
119618e
Correcting unit-tests
satr Dec 9, 2024
6bc9ef7
Correcting unit-tests
satr Dec 9, 2024
cbff180
Correcting unit-tests
satr Dec 9, 2024
9962370
Correcting unit-tests
satr Dec 9, 2024
0e892d4
Correcting unit-tests
satr Dec 9, 2024
bf3d0a9
Correcting unit-tests
satr Dec 9, 2024
bfde517
Correcting unit-tests
satr Dec 10, 2024
b2bcb85
Correcting unit-tests
satr Dec 10, 2024
6c95cb4
Merge remote-tracking branch 'origin/master' into refactor-volume-mou…
satr Dec 12, 2024
a6d960e
Fixing unit-tests
satr Dec 12, 2024
88c2246
Updated ref
satr Dec 12, 2024
b79f6bc
Updated ref
satr Dec 13, 2024
124570b
Fixed unit tests
satr Dec 13, 2024
a7d09df
Fixed unit tests
satr Dec 13, 2024
f2ce6be
Fixed unit tests
satr Dec 13, 2024
5554640
Added yq install
satr Dec 16, 2024
1fc3ac6
Restored tests
satr Dec 16, 2024
0ed4852
Fixed comparison of existing auto-provisioned and manually created pv-s
satr Dec 19, 2024
c3e8c15
Merge remote-tracking branch 'origin/master' into refactor-volume-mou…
satr Dec 19, 2024
5f88172
Removed deploy receiver from volumes
satr Dec 19, 2024
36606ce
Moving volumounts to own package
satr Dec 19, 2024
143d551
Moving volumounts to own package
satr Dec 20, 2024
f0c4ae0
Fixing volumes for jobs
satr Dec 20, 2024
7461bd8
Fixing not created job aux deployment
satr Jan 2, 2025
325c24f
Fixed not created job volumes
satr Jan 3, 2025
6dec631
Extended job aux resource
satr Jan 3, 2025
89b154f
Merge remote-tracking branch 'origin/extend-job-aux-resource' into re…
satr Jan 3, 2025
8a9d402
Extended job aux resource
satr Jan 3, 2025
a792f6f
Merge remote-tracking branch 'origin/extend-job-aux-resource' into re…
satr Jan 3, 2025
f92d84b
Cleanup
satr Jan 3, 2025
6a33899
Merge remote-tracking branch 'origin/master' into refactor-volume-mou…
satr Jan 3, 2025
f8208d6
Cleanup
satr Jan 3, 2025
b649fe0
Reuse of job aux volumes
satr Jan 3, 2025
1ce04a3
Fixed unit-tests
satr Jan 6, 2025
47a5caa
Fixing unit-tests
satr Jan 6, 2025
7516794
Fixing unit-tests
satr Jan 6, 2025
10e36f3
Fixing unit-tests
satr Jan 6, 2025
a33a865
Fixing unit-tests
satr Jan 7, 2025
0ec6425
Fixing unit-tests
satr Jan 7, 2025
900425a
Reuse existing pv and pvc for re-deployed job component
satr Jan 7, 2025
f87512d
Reuse existing pv and pvc for re-deployed job component
satr Jan 7, 2025
bcd6e67
Fixed replace of existing pv and pvc for changed volumeMount
satr Jan 8, 2025
8a896d4
Fixed replace of existing pv and pvc for changed volumeMount in job aux
satr Jan 8, 2025
a27e812
Set version. Cleanup
satr Jan 9, 2025
2c55285
Cleanup
satr Jan 9, 2025
8f10ac6
Uncommented unit-tests, fixed linter reported issues
satr Jan 10, 2025
e923201
Fixed unit-tests
satr Jan 10, 2025
ac69182
Correcting pv-pvc re-creation logic
satr Jan 13, 2025
b20aa7c
Correcting unit-tests
satr Jan 14, 2025
c05a0b8
Correcting unit-tests
satr Jan 14, 2025
d07121e
Cleaned outdated code
satr Jan 14, 2025
29f80a7
Cleaned outdated code
satr Jan 14, 2025
dcbb528
Cleanup
satr Jan 14, 2025
40a51e2
Cleanup
satr Jan 14, 2025
fe6adaa
Corrected comments. Deleted not supported AzureFile type and property
satr Jan 22, 2025
aa5cb3b
Suppressed linter alerts
satr Jan 22, 2025
3a30d28
Code cleanup
satr Jan 24, 2025
e8b0961
Corrected unit-tests
satr Jan 28, 2025
3d68ed4
Corrected unit-tests
satr Jan 28, 2025
ec7ce48
Adding unit-tests
satr Jan 28, 2025
42d1071
Adding unit-tests
satr Jan 28, 2025
b272875
Adding unit-tests
satr Jan 28, 2025
ac087a0
Adding unit-tests
satr Jan 28, 2025
52ce65d
Adding unit-tests
satr Jan 29, 2025
8bc1599
Merge remote-tracking branch 'origin/master' into refactor-volume-mou…
satr Jan 29, 2025
790c3d3
Adding unit-tests
satr Jan 29, 2025
7f4d71e
Adding unit-tests
satr Jan 29, 2025
d6c3503
Ignore comparison of pv volumes. Do not use lister to get jop-aux dep…
satr Jan 29, 2025
3cfebf7
Moved StorageAccount and ResourceGroup props in volumes
satr Jan 29, 2025
0018b2b
Moved storageaccount volumemounts properties to blobfuse2
satr Jan 30, 2025
7578abd
Removed outdated fields from the radix volume mount type
satr Feb 4, 2025
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
16 changes: 16 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,19 @@ generate: bootstrap code-gen crds mocks
verify-generate: bootstrap generate
git diff --exit-code

.PHONY: apply-ra
apply-ra: bootstrap
kubectl apply -f ./charts/radix-operator/templates/radixapplication.yaml

.PHONY: apply-rd
apply-rd: bootstrap
kubectl apply -f ./charts/radix-operator/templates/radixdeployment.yaml

HAS_GOLANGCI_LINT := $(shell command -v golangci-lint;)
HAS_MOCKGEN := $(shell command -v mockgen;)
HAS_CONTROLLER_GEN := $(shell command -v controller-gen;)
HAS_YQ := $(shell command -v yq;)
HAS_KUBECTL := $(shell command -v kubectl;)

.PHONY: bootstrap
bootstrap: vendor
Expand All @@ -185,3 +195,9 @@ endif
ifndef HAS_CONTROLLER_GEN
go install sigs.k8s.io/controller-tools/cmd/[email protected]
endif
ifndef HAS_YQ
go install github.com/mikefarah/yq/v4@latest
endif
ifndef HAS_KUBECTL
go install k8s.io/kubernetes/cmd/kubectl@latest
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.48.4
appVersion: 1.68.4
version: 1.49.0
appVersion: 1.69.0
kubeVersion: ">=1.24.0"
description: Radix Operator
keywords:
Expand Down
379 changes: 140 additions & 239 deletions charts/radix-operator/templates/radixapplication.yaml

Large diffs are not rendered by default.

184 changes: 68 additions & 116 deletions charts/radix-operator/templates/radixdeployment.yaml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ toolchain go1.22.5
require (
dario.cat/mergo v1.0.1
github.com/cert-manager/cert-manager v1.15.4
github.com/equinor/radix-common v1.9.4
github.com/equinor/radix-common v1.9.5
github.com/golang/mock v1.6.0
github.com/google/go-cmp v0.6.0
github.com/google/uuid v1.6.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/emicklei/go-restful/v3 v3.12.1 h1:PJMDIM/ak7btuL8Ex0iYET9hxM3CI2sjZtzpL63nKAU=
github.com/emicklei/go-restful/v3 v3.12.1/go.mod h1:6n3XBCmQQb25CM2LCACGz8ukIrRry+4bhvbpWn3mrbc=
github.com/equinor/radix-common v1.9.4 h1:ErSnB2tqlRwaQuQdaA0qzsReDtHDgubcvqRO098ncEw=
github.com/equinor/radix-common v1.9.4/go.mod h1:+g0Wj0D40zz29DjNkYKVmCVeYy4OsFWKI7Qi9rA6kpY=
github.com/equinor/radix-common v1.9.5 h1:p1xldkYUoavwIMguoxxOyVkOXLPA6K8qMsgzeztQtQw=
github.com/equinor/radix-common v1.9.5/go.mod h1:+g0Wj0D40zz29DjNkYKVmCVeYy4OsFWKI7Qi9rA6kpY=
github.com/evanphx/json-patch v5.9.0+incompatible h1:fBXyNpNMuTTDdquAq/uisOr2lShz4oaXpDTX2bLe7ls=
github.com/evanphx/json-patch v5.9.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk=
github.com/evanphx/json-patch/v5 v5.9.0 h1:kcBlZQbplgElYIlo/n1hJbls2z/1awpXxpRi0/FOJfg=
Expand Down
354 changes: 121 additions & 233 deletions json-schema/radixapplication.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pipeline-runner/internal/jobs/build/acr.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func NewACR() JobsBuilder {

type acr struct{}

func (c *acr) BuildJobs(useBuildCache bool, pipelineArgs model.PipelineArguments, cloneURL, gitCommitHash, gitTags string, componentImages []pipeline.BuildComponentImage, buildSecrets []string) []batchv1.Job {
func (c *acr) BuildJobs(_ bool, pipelineArgs model.PipelineArguments, cloneURL, gitCommitHash, gitTags string, componentImages []pipeline.BuildComponentImage, buildSecrets []string) []batchv1.Job {
props := &acrKubeJobProps{
pipelineArgs: pipelineArgs,
componentImages: componentImages,
Expand Down
2 changes: 1 addition & 1 deletion pipeline-runner/internal/test/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ package test
import (
"context"

"github.com/equinor/radix-operator/pipeline-runner/internal/hash"
"github.com/equinor/radix-operator/pipeline-runner/model"
pipelineDefaults "github.com/equinor/radix-operator/pipeline-runner/model/defaults"
"github.com/equinor/radix-operator/pkg/apis/defaults"
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/hash"
"gopkg.in/yaml.v3"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down
5 changes: 3 additions & 2 deletions pipeline-runner/steps/applyconfig/step.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
validate "github.com/equinor/radix-operator/pkg/apis/radixvalidators"
operatorutils "github.com/equinor/radix-operator/pkg/apis/utils"
"github.com/equinor/radix-operator/pkg/apis/utils/git"
"github.com/equinor/radix-operator/pkg/apis/utils/hash"
"github.com/rs/zerolog/log"
corev1 "k8s.io/api/core/v1"
kubeerrors "k8s.io/apimachinery/pkg/api/errors"
Expand Down Expand Up @@ -401,7 +402,7 @@ func isRadixConfigNewOrModifiedSinceDeployment(ctx context.Context, rd *radixv1.
if len(currentRdConfigHash) == 0 {
return true, nil
}
hashEqual, err := internal.CompareRadixApplicationHash(currentRdConfigHash, ra)
hashEqual, err := hash.CompareRadixApplicationHash(currentRdConfigHash, ra)
if !hashEqual && err == nil {
log.Ctx(ctx).Info().Msgf("RadixApplication updated since last deployment to environment %s", rd.Spec.Environment)
}
Expand All @@ -416,7 +417,7 @@ func isBuildSecretNewOrModifiedSinceDeployment(ctx context.Context, rd *radixv1.
if len(targetHash) == 0 {
return true, nil
}
hashEqual, err := internal.CompareBuildSecretHash(targetHash, buildSecret)
hashEqual, err := hash.CompareBuildSecretHash(targetHash, buildSecret)
if !hashEqual && err == nil {
log.Ctx(ctx).Info().Msgf("Build secrets updated since last deployment to environment %s", rd.Spec.Environment)
}
Expand Down
5 changes: 3 additions & 2 deletions pipeline-runner/steps/deploy/step.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/equinor/radix-operator/pipeline-runner/steps/internal"
"github.com/equinor/radix-operator/pkg/apis/pipeline"
"github.com/equinor/radix-operator/pkg/apis/utils"
"github.com/equinor/radix-operator/pkg/apis/utils/hash"
"github.com/rs/zerolog/log"
k8serrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -76,12 +77,12 @@ func (cli *DeployStepImplementation) deployToEnv(ctx context.Context, appName, e
commitID = pipelineInfo.PipelineArguments.CommitID // Commit ID specified by job arguments
}

radixApplicationHash, err := internal.CreateRadixApplicationHash(pipelineInfo.RadixApplication)
radixApplicationHash, err := hash.CreateRadixApplicationHash(pipelineInfo.RadixApplication)
if err != nil {
return err
}

buildSecretHash, err := internal.CreateBuildSecretHash(pipelineInfo.BuildSecret)
buildSecretHash, err := hash.CreateBuildSecretHash(pipelineInfo.BuildSecret)
if err != nil {
return err
}
Expand Down
6 changes: 3 additions & 3 deletions pipeline-runner/steps/deployconfig/step_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ import (
"github.com/equinor/radix-operator/pipeline-runner/internal/watcher"
"github.com/equinor/radix-operator/pipeline-runner/model"
"github.com/equinor/radix-operator/pipeline-runner/steps/deployconfig"
"github.com/equinor/radix-operator/pipeline-runner/steps/internal"
"github.com/equinor/radix-operator/pkg/apis/kube"
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/hash"
radixfake "github.com/equinor/radix-operator/pkg/client/clientset/versioned/fake"
"github.com/golang/mock/gomock"
kedafake "github.com/kedacore/keda/v2/pkg/generated/clientset/versioned/fake"
Expand Down Expand Up @@ -683,8 +683,8 @@ func (s *deployConfigTestSuite) createRadixDeployments(deploymentBuildersProps [
}

func (s *deployConfigTestSuite) buildRadixDeployments(deploymentBuildersProps []radixDeploymentBuildersProps, ra *radixv1.RadixApplication, sourceEnvMap map[string]radixv1.RadixDeployment) []radixv1.RadixDeployment {
radixConfigHash, _ := internal.CreateRadixApplicationHash(ra)
buildSecretHash, _ := internal.CreateBuildSecretHash(nil)
radixConfigHash, _ := hash.CreateRadixApplicationHash(ra)
buildSecretHash, _ := hash.CreateBuildSecretHash(nil)
var rdList []radixv1.RadixDeployment
for _, rdProps := range deploymentBuildersProps {
if sourceRd, ok := sourceEnvMap[rdProps.envName]; ok {
Expand Down
2 changes: 1 addition & 1 deletion pipeline-runner/steps/internal/deployment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func TestConstructForTargetEnvironment_PicksTheCorrectEnvironmentConfig(t *testi
}).
WithVolumeMounts([]radixv1.RadixVolumeMount{
{
Type: radixv1.MountTypeBlob,
Type: radixv1.MountTypeBlobFuse2FuseCsiAzure,
Container: "some-container",
Path: "some-path",
},
Expand Down
43 changes: 0 additions & 43 deletions pipeline-runner/steps/internal/hash.go

This file was deleted.

48 changes: 19 additions & 29 deletions pkg/apis/batch/kubejob.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
operatorUtils "github.com/equinor/radix-operator/pkg/apis/utils"
"github.com/equinor/radix-operator/pkg/apis/utils/annotations"
radixlabels "github.com/equinor/radix-operator/pkg/apis/utils/labels"
"github.com/equinor/radix-operator/pkg/apis/volumemount"
batchv1 "k8s.io/api/batch/v1"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/errors"
Expand All @@ -27,7 +28,7 @@ const (
jobPayloadVolumeName = "job-payload"
)

func (s *syncer) reconcileKubeJob(ctx context.Context, batchJob *radixv1.RadixBatchJob, rd *radixv1.RadixDeployment, jobComponent *radixv1.RadixDeployJobComponent, existingJobs []*batchv1.Job) error {
func (s *syncer) reconcileKubeJob(ctx context.Context, batchJob *radixv1.RadixBatchJob, rd *radixv1.RadixDeployment, jobComponent *radixv1.RadixDeployJobComponent, existingJobs []*batchv1.Job, volumes []corev1.Volume) error {
batchJobKubeJobs := slice.FindAll(existingJobs, isKubeJobForBatchJob(batchJob))

if isBatchJobStopRequested(batchJob) {
Expand All @@ -51,7 +52,7 @@ func (s *syncer) reconcileKubeJob(ctx context.Context, batchJob *radixv1.RadixBa
return err
}

job, err := s.buildJob(ctx, batchJob, jobComponent, rd)
job, err := s.buildJob(ctx, batchJob, jobComponent, rd, volumes)
if err != nil {
return err
}
Expand Down Expand Up @@ -92,19 +93,14 @@ func (s *syncer) deleteJobs(ctx context.Context, jobsToDelete []*batchv1.Job) er
return nil
}

func (s *syncer) buildJob(ctx context.Context, batchJob *radixv1.RadixBatchJob, jobComponent *radixv1.RadixDeployJobComponent, rd *radixv1.RadixDeployment) (*batchv1.Job, error) {
func (s *syncer) buildJob(ctx context.Context, batchJob *radixv1.RadixBatchJob, jobComponent *radixv1.RadixDeployJobComponent, rd *radixv1.RadixDeployment, volumes []corev1.Volume) (*batchv1.Job, error) {
jobLabels := s.batchJobIdentifierLabel(batchJob.Name, rd.Spec.AppName)
podLabels := radixlabels.Merge(
jobLabels,
radixlabels.ForPodWithRadixIdentity(jobComponent.Identity),
)
podAnnotations := annotations.ForClusterAutoscalerSafeToEvict(false)

volumes, err := s.getVolumes(ctx, rd.GetNamespace(), rd.Spec.Environment, batchJob, jobComponent, rd.Name)
if err != nil {
return nil, err
}

kubeJobName := getKubeJobName(s.radixBatch.GetName(), batchJob.Name)
containers, err := s.getContainers(ctx, rd, jobComponent, batchJob, kubeJobName)
if err != nil {
Expand Down Expand Up @@ -135,6 +131,7 @@ func (s *syncer) buildJob(ctx context.Context, batchJob *radixv1.RadixBatchJob,
}

serviceAccountSpec := deployment.NewServiceAccountSpec(rd, jobComponent)
volumes = s.appendPayloadSecretVolumes(batchJob, jobComponent, volumes)

job := &batchv1.Job{
ObjectMeta: metav1.ObjectMeta{
Expand Down Expand Up @@ -167,7 +164,6 @@ func (s *syncer) buildJob(ctx context.Context, batchJob *radixv1.RadixBatchJob,
TTLSecondsAfterFinished: pointers.Ptr(int32(86400)), // delete completed job after 24 hours
},
}

return job, nil
}

Expand All @@ -179,27 +175,21 @@ func (s *syncer) getJobPodImagePullSecrets(rd *radixv1.RadixDeployment) []corev1
return imagePullSecrets
}

func (s *syncer) getVolumes(ctx context.Context, namespace, environment string, batchJob *radixv1.RadixBatchJob, radixJobComponent *radixv1.RadixDeployJobComponent, radixDeploymentName string) ([]corev1.Volume, error) {
volumes, err := deployment.GetVolumes(ctx, s.kubeClient, s.kubeUtil, namespace, environment, radixJobComponent, radixDeploymentName)
if err != nil {
return nil, err
}

if radixJobComponent.Payload != nil && batchJob.PayloadSecretRef != nil {
volumes = append(volumes, corev1.Volume{
Name: jobPayloadVolumeName,
VolumeSource: corev1.VolumeSource{
Secret: &corev1.SecretVolumeSource{
SecretName: batchJob.PayloadSecretRef.Name,
Items: []corev1.KeyToPath{
{Key: batchJob.PayloadSecretRef.Key, Path: "payload"},
},
func (s *syncer) appendPayloadSecretVolumes(batchJob *radixv1.RadixBatchJob, radixJobComponent *radixv1.RadixDeployJobComponent, volumes []corev1.Volume) []corev1.Volume {
if radixJobComponent.Payload == nil || batchJob.PayloadSecretRef == nil {
return volumes
}
return append(volumes, corev1.Volume{
Name: jobPayloadVolumeName,
VolumeSource: corev1.VolumeSource{
Secret: &corev1.SecretVolumeSource{
SecretName: batchJob.PayloadSecretRef.Name,
Items: []corev1.KeyToPath{
{Key: batchJob.PayloadSecretRef.Key, Path: "payload"},
},
},
})
}

return volumes, nil
},
})
}

func (s *syncer) getContainers(ctx context.Context, rd *radixv1.RadixDeployment, jobComponent *radixv1.RadixDeployJobComponent, batchJob *radixv1.RadixBatchJob, kubeJobName string) ([]corev1.Container, error) {
Expand Down Expand Up @@ -276,7 +266,7 @@ func getContainerPorts(radixJobComponent *radixv1.RadixDeployJobComponent) []cor
}

func (s *syncer) getContainerVolumeMounts(batchJob *radixv1.RadixBatchJob, radixJobComponent *radixv1.RadixDeployJobComponent, radixDeploymentName string) ([]corev1.VolumeMount, error) {
volumeMounts, err := deployment.GetRadixDeployComponentVolumeMounts(radixJobComponent, radixDeploymentName)
volumeMounts, err := volumemount.GetRadixDeployComponentVolumeMounts(radixJobComponent, radixDeploymentName)
if err != nil {
return nil, err
}
Expand Down
20 changes: 17 additions & 3 deletions pkg/apis/batch/syncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/equinor/radix-operator/pkg/apis/kube"
radixv1 "github.com/equinor/radix-operator/pkg/apis/radix/v1"
radixlabels "github.com/equinor/radix-operator/pkg/apis/utils/labels"
"github.com/equinor/radix-operator/pkg/apis/volumemount"
radixclient "github.com/equinor/radix-operator/pkg/client/clientset/versioned"
"github.com/rs/zerolog/log"
"k8s.io/apimachinery/pkg/api/errors"
Expand Down Expand Up @@ -86,22 +87,35 @@ func (s *syncer) reconcile(ctx context.Context) error {
return err
}

existingJobs, err := s.kubeUtil.ListJobsWithSelector(ctx, s.radixBatch.GetNamespace(), s.batchIdentifierLabel().String())
namespace := s.radixBatch.GetNamespace()
existingJobs, err := s.kubeUtil.ListJobsWithSelector(ctx, namespace, s.batchIdentifierLabel().String())
if err != nil {
return err
}

existingServices, err := s.kubeUtil.ListServicesWithSelector(ctx, s.radixBatch.GetNamespace(), s.batchIdentifierLabel().String())
existingServices, err := s.kubeUtil.ListServicesWithSelector(ctx, namespace, s.batchIdentifierLabel().String())
if err != nil {
return err
}
existingVolumes, err := volumemount.GetExistingJobAuxComponentVolumes(ctx, s.kubeUtil, namespace, jobComponent.GetName())
if err != nil {
return err
}
desiredVolumes, err := volumemount.GetVolumes(ctx, s.kubeUtil, namespace, jobComponent, rd.Name, existingVolumes)
if err != nil {
return err
}
actualVolumes, err := volumemount.CreateOrUpdateCsiAzureVolumeResourcesForDeployComponent(ctx, s.kubeUtil.KubeClient(), rd, namespace, jobComponent, desiredVolumes)
if err != nil {
return fmt.Errorf("failed to create or update csi azure volume resources: %w", err)
}

for i, batchJob := range s.radixBatch.Spec.Jobs {
if err := s.reconcileService(ctx, &batchJob, rd, jobComponent, existingServices); err != nil {
return fmt.Errorf("batchjob %s: failed to reconcile service: %w", batchJob.Name, err)
}

if err := s.reconcileKubeJob(ctx, &batchJob, rd, jobComponent, existingJobs); err != nil {
if err := s.reconcileKubeJob(ctx, &batchJob, rd, jobComponent, existingJobs, actualVolumes); err != nil {
return fmt.Errorf("batchjob %s: failed to reconcile kubejob: %w", batchJob.Name, err)
}

Expand Down
Loading
Loading