From d94ba3c7b4ea68e010631ccfea4e611beb881e87 Mon Sep 17 00:00:00 2001 From: Jake Date: Thu, 24 Aug 2023 13:03:12 +0100 Subject: [PATCH] fix: store workload contents as string not []byte --- api/v1alpha1/work_types.go | 2 +- api/v1alpha1/zz_generated.deepcopy.go | 9 +-------- charts/kratix/crds/platform_kratix_io_crds.yaml | 2 -- config/crd/bases/platform.kratix.io_workplacements.yaml | 1 - config/crd/bases/platform.kratix.io_works.yaml | 1 - controllers/promise_controller.go | 2 +- controllers/workplacement_controller.go | 2 +- work-creator/pipeline/work_creator.go | 2 +- work-creator/pipeline/work_creator_test.go | 2 +- 9 files changed, 6 insertions(+), 17 deletions(-) diff --git a/api/v1alpha1/work_types.go b/api/v1alpha1/work_types.go index 7e830616..d8a9a12d 100644 --- a/api/v1alpha1/work_types.go +++ b/api/v1alpha1/work_types.go @@ -88,7 +88,7 @@ func (w *Work) GetSchedulingSelectors() map[string]string { type Workload struct { // +optional Filepath string `json:"filepath,omitempty"` - Content []byte `json:"content,omitempty"` + Content string `json:"content,omitempty"` } //+kubebuilder:object:root=true diff --git a/api/v1alpha1/zz_generated.deepcopy.go b/api/v1alpha1/zz_generated.deepcopy.go index 7fdf30d2..c253609a 100644 --- a/api/v1alpha1/zz_generated.deepcopy.go +++ b/api/v1alpha1/zz_generated.deepcopy.go @@ -790,11 +790,6 @@ func (in *Workflows) DeepCopy() *Workflows { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *Workload) DeepCopyInto(out *Workload) { *out = *in - if in.Content != nil { - in, out := &in.Content, &out.Content - *out = make([]byte, len(*in)) - copy(*out, *in) - } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Workload. @@ -813,9 +808,7 @@ func (in *WorkloadCoreFields) DeepCopyInto(out *WorkloadCoreFields) { if in.Workloads != nil { in, out := &in.Workloads, &out.Workloads *out = make([]Workload, len(*in)) - for i := range *in { - (*in)[i].DeepCopyInto(&(*out)[i]) - } + copy(*out, *in) } } diff --git a/charts/kratix/crds/platform_kratix_io_crds.yaml b/charts/kratix/crds/platform_kratix_io_crds.yaml index 719b587c..c1076212 100644 --- a/charts/kratix/crds/platform_kratix_io_crds.yaml +++ b/charts/kratix/crds/platform_kratix_io_crds.yaml @@ -310,7 +310,6 @@ spec: description: Workload represents the manifest workload to be deployed on destination properties: content: - format: byte type: string filepath: type: string @@ -392,7 +391,6 @@ spec: description: Workload represents the manifest workload to be deployed on destination properties: content: - format: byte type: string filepath: type: string diff --git a/config/crd/bases/platform.kratix.io_workplacements.yaml b/config/crd/bases/platform.kratix.io_workplacements.yaml index 04d30117..b9aafa93 100644 --- a/config/crd/bases/platform.kratix.io_workplacements.yaml +++ b/config/crd/bases/platform.kratix.io_workplacements.yaml @@ -48,7 +48,6 @@ spec: on destination properties: content: - format: byte type: string filepath: type: string diff --git a/config/crd/bases/platform.kratix.io_works.yaml b/config/crd/bases/platform.kratix.io_works.yaml index 9978ee65..7bbfaa7f 100644 --- a/config/crd/bases/platform.kratix.io_works.yaml +++ b/config/crd/bases/platform.kratix.io_works.yaml @@ -71,7 +71,6 @@ spec: on destination properties: content: - format: byte type: string filepath: type: string diff --git a/controllers/promise_controller.go b/controllers/promise_controller.go index d836591b..88999808 100644 --- a/controllers/promise_controller.go +++ b/controllers/promise_controller.go @@ -534,7 +534,7 @@ func (r *PromiseReconciler) createWorkResourceForDependencies(ctx context.Contex work.Spec.Workloads = []v1alpha1.Workload{ { - Content: yamlBytes, + Content: string(yamlBytes), Filepath: "static/dependencies.yaml", }, } diff --git a/controllers/workplacement_controller.go b/controllers/workplacement_controller.go index 93f08034..5d767423 100644 --- a/controllers/workplacement_controller.go +++ b/controllers/workplacement_controller.go @@ -126,7 +126,7 @@ func (r *WorkPlacementReconciler) deleteWorkPlacement(ctx context.Context, write func (r *WorkPlacementReconciler) writeWorkloadsToStateStore(writer writers.StateStoreWriter, workPlacement v1alpha1.WorkPlacement, logger logr.Logger) error { for _, workload := range workPlacement.Spec.Workloads { filepath := filepath.Join(getDir(workPlacement), workload.Filepath) - err := writer.WriteObject(filepath, workload.Content) + err := writer.WriteObject(filepath, []byte(workload.Content)) if err != nil { logger.Error(err, "Error writing resources to repository", "filepath", filepath) return err diff --git a/work-creator/pipeline/work_creator.go b/work-creator/pipeline/work_creator.go index 500c641e..12ba1a77 100644 --- a/work-creator/pipeline/work_creator.go +++ b/work-creator/pipeline/work_creator.go @@ -121,7 +121,7 @@ func (w *WorkCreator) getWorkloadsFromDir(prefixToTrimFromWorkloadFilepath, root } workload := platformv1alpha1.Workload{ - Content: byteValue, + Content: string(byteValue), Filepath: path, } diff --git a/work-creator/pipeline/work_creator_test.go b/work-creator/pipeline/work_creator_test.go index 5fa26933..0d1a8302 100644 --- a/work-creator/pipeline/work_creator_test.go +++ b/work-creator/pipeline/work_creator_test.go @@ -86,7 +86,7 @@ var _ = Describe("WorkCreator", func() { for _, workload := range workResource.Spec.Workloads { fileContent, err := ioutil.ReadFile(filepath.Join(mockPipelineDirectory, "input", workload.Filepath)) Expect(err).NotTo(HaveOccurred()) - Expect(workload.Content).To(Equal(fileContent)) + Expect(workload.Content).To(Equal(string(fileContent))) } }) })