From c0737a94b3a3c35a8d87c9e4c078476de1d580e6 Mon Sep 17 00:00:00 2001 From: Todd Ritchie Date: Tue, 19 Oct 2021 13:44:57 -0400 Subject: [PATCH] Move runtemplate from ns scoped to cluster scoped, rename to ClusterRunTemplate [#197] Co-authored-by: Sam Coward --- ...aml => carto.run_clusterruntemplates.yaml} | 12 +- config/crd/bases/carto.run_pipelines.yaml | 2 - ...un_template.go => cluster_run_template.go} | 15 +- pkg/apis/v1alpha1/pipeline.go | 3 +- pkg/apis/v1alpha1/pipeline_test.go | 8 - pkg/apis/v1alpha1/zz_generated.deepcopy.go | 162 +++++++++--------- pkg/controller/pipeline/reconciler_test.go | 5 +- pkg/realizer/pipeline/conditions.go | 2 +- pkg/realizer/pipeline/realizer.go | 13 +- pkg/realizer/pipeline/realizer_test.go | 36 ++-- pkg/registrar/map_functions.go | 18 +- pkg/registrar/map_functions_test.go | 37 +--- pkg/registrar/registrar.go | 2 +- pkg/registrar/registrar_test.go | 2 +- pkg/repository/repository.go | 10 +- pkg/repository/repository_test.go | 26 +-- .../repositoryfakes/fake_repository.go | 20 +-- ...un_template.go => cluster_run_template.go} | 6 +- ...e_test.go => cluster_run_template_test.go} | 6 +- rfc/rfc-0013-delivery.md | 2 +- .../pipeline_service/pipeline_service_test.go | 20 +-- .../pipeline-service/CRDs/00-assert.yaml | 4 +- .../pipeline-service/default/00-assert.yaml | 2 +- .../default/00-run-template.yaml | 2 +- .../default/03-run-template.yaml | 2 +- .../multi-label-selector/00-run-template.yaml | 2 +- .../pipeline-with-inputs/00-run-template.yaml | 2 +- .../00-run-template.yaml | 2 +- .../00-run-template.yaml | 4 +- .../00-templates.yaml | 2 +- 30 files changed, 179 insertions(+), 250 deletions(-) rename config/crd/bases/{carto.run_runtemplates.yaml => carto.run_clusterruntemplates.yaml} (92%) rename pkg/apis/v1alpha1/{run_template.go => cluster_run_template.go} (79%) rename pkg/templates/{run_template.go => cluster_run_template.go} (96%) rename pkg/templates/{run_template_test.go => cluster_run_template_test.go} (98%) diff --git a/config/crd/bases/carto.run_runtemplates.yaml b/config/crd/bases/carto.run_clusterruntemplates.yaml similarity index 92% rename from config/crd/bases/carto.run_runtemplates.yaml rename to config/crd/bases/carto.run_clusterruntemplates.yaml index bfb3bb1cb..e5dea73d2 100644 --- a/config/crd/bases/carto.run_runtemplates.yaml +++ b/config/crd/bases/carto.run_clusterruntemplates.yaml @@ -20,15 +20,15 @@ metadata: annotations: controller-gen.kubebuilder.io/version: v0.7.0 creationTimestamp: null - name: runtemplates.carto.run + name: clusterruntemplates.carto.run spec: group: carto.run names: - kind: RunTemplate - listKind: RunTemplateList - plural: runtemplates - singular: runtemplate - scope: Namespaced + kind: ClusterRunTemplate + listKind: ClusterRunTemplateList + plural: clusterruntemplates + singular: clusterruntemplate + scope: Cluster versions: - name: v1alpha1 schema: diff --git a/config/crd/bases/carto.run_pipelines.yaml b/config/crd/bases/carto.run_pipelines.yaml index c5a414998..5298544b4 100644 --- a/config/crd/bases/carto.run_pipelines.yaml +++ b/config/crd/bases/carto.run_pipelines.yaml @@ -59,8 +59,6 @@ spec: name: minLength: 1 type: string - namespace: - type: string required: - name type: object diff --git a/pkg/apis/v1alpha1/run_template.go b/pkg/apis/v1alpha1/cluster_run_template.go similarity index 79% rename from pkg/apis/v1alpha1/run_template.go rename to pkg/apis/v1alpha1/cluster_run_template.go index 9a7100a31..5cccd914c 100644 --- a/pkg/apis/v1alpha1/run_template.go +++ b/pkg/apis/v1alpha1/cluster_run_template.go @@ -24,14 +24,15 @@ import ( ) // +kubebuilder:object:root=true +// +kubebuilder:resource:scope=Cluster -type RunTemplate struct { +type ClusterRunTemplate struct { metav1.TypeMeta `json:",inline"` metav1.ObjectMeta `json:"metadata"` - Spec RunTemplateSpec `json:"spec"` + Spec ClusterRunTemplateSpec `json:"spec"` } -type RunTemplateSpec struct { +type ClusterRunTemplateSpec struct { // +kubebuilder:pruning:PreserveUnknownFields Template runtime.RawExtension `json:"template"` Outputs map[string]string `json:"outputs,omitempty"` @@ -39,15 +40,15 @@ type RunTemplateSpec struct { // +kubebuilder:object:root=true -type RunTemplateList struct { +type ClusterRunTemplateList struct { metav1.TypeMeta `json:",inline"` metav1.ListMeta `json:"metadata,omitempty"` - Items []RunTemplate `json:"items"` + Items []ClusterRunTemplate `json:"items"` } func init() { SchemeBuilder.Register( - &RunTemplate{}, - &RunTemplateList{}, + &ClusterRunTemplate{}, + &ClusterRunTemplateList{}, ) } diff --git a/pkg/apis/v1alpha1/pipeline.go b/pkg/apis/v1alpha1/pipeline.go index eba85572c..e78e5ab0b 100644 --- a/pkg/apis/v1alpha1/pipeline.go +++ b/pkg/apis/v1alpha1/pipeline.go @@ -73,8 +73,7 @@ type ResourceType struct { type TemplateReference struct { Kind string `json:"kind,omitempty"` // +kubebuilder:validation:MinLength=1 - Name string `json:"name"` - Namespace string `json:"namespace,omitempty"` + Name string `json:"name"` } // +kubebuilder:object:root=true diff --git a/pkg/apis/v1alpha1/pipeline_test.go b/pkg/apis/v1alpha1/pipeline_test.go index 26bddec83..6ff0e66a1 100644 --- a/pkg/apis/v1alpha1/pipeline_test.go +++ b/pkg/apis/v1alpha1/pipeline_test.go @@ -68,13 +68,5 @@ var _ = Describe("Pipeline", func() { Expect(jsonValue).To(ContainSubstring("kind")) Expect(jsonValue).To(ContainSubstring("omitempty")) }) - - It("requires a namespace", func() { - namespaceField, found := templateReferenceType.FieldByName("Namespace") - Expect(found).To(BeTrue()) - jsonValue := namespaceField.Tag.Get("json") - Expect(jsonValue).To(ContainSubstring("namespace")) - Expect(jsonValue).To(ContainSubstring("omitempty")) - }) }) }) diff --git a/pkg/apis/v1alpha1/zz_generated.deepcopy.go b/pkg/apis/v1alpha1/zz_generated.deepcopy.go index be3fbe86e..7fe621e0a 100644 --- a/pkg/apis/v1alpha1/zz_generated.deepcopy.go +++ b/pkg/apis/v1alpha1/zz_generated.deepcopy.go @@ -306,6 +306,87 @@ func (in *ClusterImageTemplateList) DeepCopyObject() runtime.Object { return nil } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *ClusterRunTemplate) DeepCopyInto(out *ClusterRunTemplate) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) + in.Spec.DeepCopyInto(&out.Spec) +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ClusterRunTemplate. +func (in *ClusterRunTemplate) DeepCopy() *ClusterRunTemplate { + if in == nil { + return nil + } + out := new(ClusterRunTemplate) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *ClusterRunTemplate) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *ClusterRunTemplateList) DeepCopyInto(out *ClusterRunTemplateList) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ListMeta.DeepCopyInto(&out.ListMeta) + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]ClusterRunTemplate, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ClusterRunTemplateList. +func (in *ClusterRunTemplateList) DeepCopy() *ClusterRunTemplateList { + if in == nil { + return nil + } + out := new(ClusterRunTemplateList) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *ClusterRunTemplateList) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *ClusterRunTemplateSpec) DeepCopyInto(out *ClusterRunTemplateSpec) { + *out = *in + in.Template.DeepCopyInto(&out.Template) + if in.Outputs != nil { + in, out := &in.Outputs, &out.Outputs + *out = make(map[string]string, len(*in)) + for key, val := range *in { + (*out)[key] = val + } + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ClusterRunTemplateSpec. +func (in *ClusterRunTemplateSpec) DeepCopy() *ClusterRunTemplateSpec { + if in == nil { + return nil + } + out := new(ClusterRunTemplateSpec) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *ClusterSourceTemplate) DeepCopyInto(out *ClusterSourceTemplate) { *out = *in @@ -781,87 +862,6 @@ func (in *ResourceType) DeepCopy() *ResourceType { return out } -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *RunTemplate) DeepCopyInto(out *RunTemplate) { - *out = *in - out.TypeMeta = in.TypeMeta - in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) - in.Spec.DeepCopyInto(&out.Spec) -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new RunTemplate. -func (in *RunTemplate) DeepCopy() *RunTemplate { - if in == nil { - return nil - } - out := new(RunTemplate) - in.DeepCopyInto(out) - return out -} - -// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *RunTemplate) DeepCopyObject() runtime.Object { - if c := in.DeepCopy(); c != nil { - return c - } - return nil -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *RunTemplateList) DeepCopyInto(out *RunTemplateList) { - *out = *in - out.TypeMeta = in.TypeMeta - in.ListMeta.DeepCopyInto(&out.ListMeta) - if in.Items != nil { - in, out := &in.Items, &out.Items - *out = make([]RunTemplate, len(*in)) - for i := range *in { - (*in)[i].DeepCopyInto(&(*out)[i]) - } - } -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new RunTemplateList. -func (in *RunTemplateList) DeepCopy() *RunTemplateList { - if in == nil { - return nil - } - out := new(RunTemplateList) - in.DeepCopyInto(out) - return out -} - -// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *RunTemplateList) DeepCopyObject() runtime.Object { - if c := in.DeepCopy(); c != nil { - return c - } - return nil -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *RunTemplateSpec) DeepCopyInto(out *RunTemplateSpec) { - *out = *in - in.Template.DeepCopyInto(&out.Template) - if in.Outputs != nil { - in, out := &in.Outputs, &out.Outputs - *out = make(map[string]string, len(*in)) - for key, val := range *in { - (*out)[key] = val - } - } -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new RunTemplateSpec. -func (in *RunTemplateSpec) DeepCopy() *RunTemplateSpec { - if in == nil { - return nil - } - out := new(RunTemplateSpec) - in.DeepCopyInto(out) - return out -} - // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *SourceTemplateSpec) DeepCopyInto(out *SourceTemplateSpec) { *out = *in diff --git a/pkg/controller/pipeline/reconciler_test.go b/pkg/controller/pipeline/reconciler_test.go index 26d550028..1e41124b7 100644 --- a/pkg/controller/pipeline/reconciler_test.go +++ b/pkg/controller/pipeline/reconciler_test.go @@ -85,9 +85,8 @@ var _ = Describe("Reconcile", func() { }, Spec: v1alpha1.PipelineSpec{ RunTemplateRef: v1alpha1.TemplateReference{ - Kind: "RunTemplateRef", - Name: "my-run-template", - Namespace: "ns1", + Kind: "RunTemplateRef", + Name: "my-run-template", }, }, }, nil) diff --git a/pkg/realizer/pipeline/conditions.go b/pkg/realizer/pipeline/conditions.go index 3b451a8b5..0cbffe61d 100644 --- a/pkg/realizer/pipeline/conditions.go +++ b/pkg/realizer/pipeline/conditions.go @@ -20,7 +20,7 @@ import ( "github.com/vmware-tanzu/cartographer/pkg/apis/v1alpha1" ) -// -- RunTemplate conditions +// -- ClusterRunTemplate conditions func RunTemplateReadyCondition() *metav1.Condition { return &metav1.Condition{ diff --git a/pkg/realizer/pipeline/realizer.go b/pkg/realizer/pipeline/realizer.go index 08c686970..187f1b91a 100644 --- a/pkg/realizer/pipeline/realizer.go +++ b/pkg/realizer/pipeline/realizer.go @@ -47,24 +47,19 @@ type TemplatingContext struct { } func (p *pipelineRealizer) Realize(ctx context.Context, pipeline *v1alpha1.Pipeline, logger logr.Logger, repository repository.Repository) (*v1.Condition, templates.Outputs, *unstructured.Unstructured) { - pipeline.Spec.RunTemplateRef.Kind = "RunTemplate" - if pipeline.Spec.RunTemplateRef.Namespace == "" { - pipeline.Spec.RunTemplateRef.Namespace = pipeline.Namespace - } + pipeline.Spec.RunTemplateRef.Kind = "ClusterRunTemplate" template, err := repository.GetRunTemplate(pipeline.Spec.RunTemplateRef) if err != nil { - errorMessage := fmt.Sprintf("could not get RunTemplate '%s'", pipeline.Spec.RunTemplateRef.Name) + errorMessage := fmt.Sprintf("could not get ClusterRunTemplate '%s'", pipeline.Spec.RunTemplateRef.Name) logger.Error(err, errorMessage) return RunTemplateMissingCondition(fmt.Errorf("%s: %w", errorMessage, err)), nil, nil } labels := map[string]string{ - "carto.run/pipeline-name": pipeline.Name, - "carto.run/pipeline-namespace": pipeline.Namespace, - "carto.run/run-template-name": template.GetName(), - "carto.run/run-template-namespace": pipeline.Spec.RunTemplateRef.Namespace, + "carto.run/pipeline-name": pipeline.Name, + "carto.run/run-template-name": template.GetName(), } selected, err := resolveSelector(pipeline.Spec.Selector, repository) diff --git a/pkg/realizer/pipeline/realizer_test.go b/pkg/realizer/pipeline/realizer_test.go index 8e8a6db54..ff0a96504 100644 --- a/pkg/realizer/pipeline/realizer_test.go +++ b/pkg/realizer/pipeline/realizer_test.go @@ -58,15 +58,14 @@ var _ = Describe("Realizer", func() { pipeline = &v1alpha1.Pipeline{ Spec: v1alpha1.PipelineSpec{ RunTemplateRef: v1alpha1.TemplateReference{ - Kind: "RunTemplate", - Name: "my-template", - Namespace: "some-ns", + Kind: "ClusterRunTemplate", + Name: "my-template", }, }, } }) - Context("with a valid RunTemplate", func() { + Context("with a valid ClusterRunTemplate", func() { BeforeEach(func() { testObj := resources.Test{ TypeMeta: metav1.TypeMeta{ @@ -93,8 +92,8 @@ var _ = Describe("Realizer", func() { dbytes, err := json.Marshal(testObj) Expect(err).ToNot(HaveOccurred()) - var templateAPI = &v1alpha1.RunTemplate{ - Spec: v1alpha1.RunTemplateSpec{ + var templateAPI = &v1alpha1.ClusterRunTemplate{ + Spec: v1alpha1.ClusterRunTemplateSpec{ Outputs: map[string]string{ "myout": "spec.foo", }, @@ -122,7 +121,7 @@ var _ = Describe("Realizer", func() { Expect(repository.GetRunTemplateCallCount()).To(Equal(1)) Expect(repository.GetRunTemplateArgsForCall(0)).To(MatchFields(IgnoreExtras, Fields{ - "Kind": Equal("RunTemplate"), + "Kind": Equal("ClusterRunTemplate"), "Name": Equal("my-template"), }, )) @@ -364,8 +363,8 @@ var _ = Describe("Realizer", func() { Context("with unsatisfied output paths", func() { BeforeEach(func() { - templateAPI := &v1alpha1.RunTemplate{ - Spec: v1alpha1.RunTemplateSpec{ + templateAPI := &v1alpha1.ClusterRunTemplate{ + Spec: v1alpha1.ClusterRunTemplateSpec{ Outputs: map[string]string{ "myout": "data.hasnot", }, @@ -418,10 +417,10 @@ var _ = Describe("Realizer", func() { }) - Context("with an invalid RunTemplate", func() { + Context("with an invalid ClusterRunTemplate", func() { BeforeEach(func() { - templateAPI := &v1alpha1.RunTemplate{ - Spec: v1alpha1.RunTemplateSpec{ + templateAPI := &v1alpha1.ClusterRunTemplate{ + Spec: v1alpha1.ClusterRunTemplateSpec{ Template: runtime.RawExtension{}, }, } @@ -451,16 +450,15 @@ var _ = Describe("Realizer", func() { }) - Context("the RunTemplate cannot be fetched", func() { + Context("the ClusterRunTemplate cannot be fetched", func() { BeforeEach(func() { repository.GetRunTemplateReturns(nil, errors.New("Errol mcErrorFace")) pipeline = &v1alpha1.Pipeline{ Spec: v1alpha1.PipelineSpec{ RunTemplateRef: v1alpha1.TemplateReference{ - Kind: "RunTemplate", - Name: "my-template", - Namespace: "some-ns", + Kind: "ClusterRunTemplate", + Name: "my-template", }, }, } @@ -469,11 +467,11 @@ var _ = Describe("Realizer", func() { It("logs the error", func() { _, _, _ = rlzr.Realize(context.TODO(), pipeline, logger, repository) - Expect(out).To(Say(`"msg":"could not get RunTemplate 'my-template'"`)) + Expect(out).To(Say(`"msg":"could not get ClusterRunTemplate 'my-template'"`)) Expect(out).To(Say(`"error":"Errol mcErrorFace"`)) }) - It("return the condition for a missing RunTemplate", func() { + It("return the condition for a missing ClusterRunTemplate", func() { condition, _, _ := rlzr.Realize(context.TODO(), pipeline, logger, repository) Expect(*condition).To( @@ -481,7 +479,7 @@ var _ = Describe("Realizer", func() { "Type": Equal("RunTemplateReady"), "Status": Equal(metav1.ConditionFalse), "Reason": Equal("RunTemplateNotFound"), - "Message": Equal("could not get RunTemplate 'my-template': Errol mcErrorFace"), + "Message": Equal("could not get ClusterRunTemplate 'my-template': Errol mcErrorFace"), }), ) }) diff --git a/pkg/registrar/map_functions.go b/pkg/registrar/map_functions.go index 1422d7f4a..be4692473 100644 --- a/pkg/registrar/map_functions.go +++ b/pkg/registrar/map_functions.go @@ -71,7 +71,7 @@ func (mapper *Mapper) ClusterSupplyChainToWorkloadRequests(object client.Object) func (mapper *Mapper) RunTemplateToPipelineRequests(object client.Object) []reconcile.Request { var err error - runTemplate, ok := object.(*v1alpha1.RunTemplate) + runTemplate, ok := object.(*v1alpha1.ClusterRunTemplate) if !ok { mapper.Logger.Error(nil, "run template to pipeline requests: cast to run template failed") return nil @@ -87,7 +87,8 @@ func (mapper *Mapper) RunTemplateToPipelineRequests(object client.Object) []reco var requests []reconcile.Request for _, pipeline := range list.Items { - if runTemplateRefMatch(pipeline.Spec.RunTemplateRef, pipeline.Namespace, runTemplate) { + + if runTemplateRefMatch(pipeline.Spec.RunTemplateRef, runTemplate) { requests = append(requests, reconcile.Request{ NamespacedName: types.NamespacedName{ Name: pipeline.Name, @@ -100,19 +101,10 @@ func (mapper *Mapper) RunTemplateToPipelineRequests(object client.Object) []reco return requests } -func runTemplateRefMatch(ref v1alpha1.TemplateReference, pipelineNamespace string, runTemplate *v1alpha1.RunTemplate) bool { +func runTemplateRefMatch(ref v1alpha1.TemplateReference, runTemplate *v1alpha1.ClusterRunTemplate) bool { if ref.Name != runTemplate.Name { return false } - if ref.Namespace != runTemplate.Namespace { - if ref.Namespace != "" { - return false - } - if pipelineNamespace != runTemplate.Namespace { - return false - } - } - - return ref.Kind == "RunTemplate" || ref.Kind == "" + return ref.Kind == "ClusterRunTemplate" || ref.Kind == "" } diff --git a/pkg/registrar/map_functions_test.go b/pkg/registrar/map_functions_test.go index 6b3f15e13..4e4b5f9bd 100644 --- a/pkg/registrar/map_functions_test.go +++ b/pkg/registrar/map_functions_test.go @@ -183,7 +183,7 @@ var _ = Describe("MapFunctions", func() { fakeClientBuilder = fake.NewClientBuilder() fakeLogger = ®istrarfakes.FakeLogger{} - runTemplate = &v1alpha1.RunTemplate{ + runTemplate = &v1alpha1.ClusterRunTemplate{ ObjectMeta: metav1.ObjectMeta{ Name: "match", Namespace: "match", @@ -245,8 +245,7 @@ var _ = Describe("MapFunctions", func() { Context("with a templateRef that specifies a namespace", func() { BeforeEach(func() { pipeline.Spec.RunTemplateRef = v1alpha1.TemplateReference{ - Name: "match", - Namespace: "match", + Name: "match", } clientObjects = []client.Object{pipeline} }) @@ -302,39 +301,11 @@ var _ = Describe("MapFunctions", func() { }) }) - Context("because the namespace in the templateRef is different", func() { - BeforeEach(func() { - pipeline.Spec.RunTemplateRef = v1alpha1.TemplateReference{ - Name: "match", - Namespace: "some-namespace", - } - clientObjects = []client.Object{pipeline} - }) - - It("returns an empty list of requests", func() { - Expect(result).To(BeEmpty()) - }) - }) - - Context("because the templateRef does not specify a namespace and the pipeline is in a different namespace from the runTemplate", func() { - BeforeEach(func() { - pipeline.Spec.RunTemplateRef = v1alpha1.TemplateReference{ - Name: "match", - } - clientObjects = []client.Object{pipeline} - }) - - It("returns an empty list of requests", func() { - Expect(result).To(BeEmpty()) - }) - }) - Context("because the templateRef is the wrong Kind", func() { BeforeEach(func() { pipeline.Spec.RunTemplateRef = v1alpha1.TemplateReference{ - Name: "match", - Namespace: "match", - Kind: "some-kind", + Name: "match", + Kind: "some-kind", } clientObjects = []client.Object{pipeline} }) diff --git a/pkg/registrar/registrar.go b/pkg/registrar/registrar.go index 74add59b5..26646ee1b 100644 --- a/pkg/registrar/registrar.go +++ b/pkg/registrar/registrar.go @@ -175,7 +175,7 @@ func registerPipelineServiceController(mgr manager.Manager) error { } if err := ctrl.Watch( - &source.Kind{Type: &v1alpha1.RunTemplate{}}, + &source.Kind{Type: &v1alpha1.ClusterRunTemplate{}}, handler.EnqueueRequestsFromMapFunc(mapper.RunTemplateToPipelineRequests), ); err != nil { return fmt.Errorf("watch: %w", err) diff --git a/pkg/registrar/registrar_test.go b/pkg/registrar/registrar_test.go index 173ce5101..bd4292de2 100644 --- a/pkg/registrar/registrar_test.go +++ b/pkg/registrar/registrar_test.go @@ -73,11 +73,11 @@ var _ = Describe("Registrar", func() { "ClusterDelivery", "ClusterDeploymentTemplate", "ClusterImageTemplate", + "ClusterRunTemplate", "ClusterSourceTemplate", "ClusterSupplyChain", "ClusterTemplate", "Pipeline", - "RunTemplate", "Workload", } diff --git a/pkg/repository/repository.go b/pkg/repository/repository.go index a81931571..097ce0a05 100644 --- a/pkg/repository/repository.go +++ b/pkg/repository/repository.go @@ -36,7 +36,7 @@ type Repository interface { EnsureObjectExistsOnCluster(obj *unstructured.Unstructured, allowUpdate bool) error GetClusterTemplate(reference v1alpha1.ClusterTemplateReference) (templates.Template, error) GetDeliveryClusterTemplate(reference v1alpha1.DeliveryClusterTemplateReference) (templates.Template, error) - GetRunTemplate(reference v1alpha1.TemplateReference) (templates.RunTemplate, error) + GetRunTemplate(reference v1alpha1.TemplateReference) (templates.ClusterRunTemplate, error) GetSupplyChainsForWorkload(workload *v1alpha1.Workload) ([]v1alpha1.ClusterSupplyChain, error) GetWorkload(name string, namespace string) (*v1alpha1.Workload, error) GetSupplyChain(name string) (*v1alpha1.ClusterSupplyChain, error) @@ -176,13 +176,11 @@ func (r *repository) GetDeliveryClusterTemplate(ref v1alpha1.DeliveryClusterTemp return template, nil } -func (r *repository) GetRunTemplate(ref v1alpha1.TemplateReference) (templates.RunTemplate, error) { - - runTemplate := &v1alpha1.RunTemplate{} +func (r *repository) GetRunTemplate(ref v1alpha1.TemplateReference) (templates.ClusterRunTemplate, error) { + runTemplate := &v1alpha1.ClusterRunTemplate{} err := r.cl.Get(context.TODO(), client.ObjectKey{ - Name: ref.Name, - Namespace: ref.Namespace, + Name: ref.Name, }, runTemplate) if err != nil { return nil, fmt.Errorf("get: %w", err) diff --git a/pkg/repository/repository_test.go b/pkg/repository/repository_test.go index 4b0258bd9..434ca7d70 100644 --- a/pkg/repository/repository_test.go +++ b/pkg/repository/repository_test.go @@ -608,41 +608,27 @@ spec: Context("GetRunTemplate", func() { BeforeEach(func() { clientObjects = []client.Object{ - &v1alpha1.RunTemplate{ + &v1alpha1.ClusterRunTemplate{ ObjectMeta: metav1.ObjectMeta{ - Name: "first-template", - Namespace: "ns1", + Name: "first-template", }, }, - &v1alpha1.RunTemplate{ + &v1alpha1.ClusterRunTemplate{ ObjectMeta: metav1.ObjectMeta{ - Name: "second-template", - Namespace: "ns2", + Name: "second-template", }, }} }) It("gets the template successfully", func() { templateRef := v1alpha1.TemplateReference{ - Kind: "RunTemplate", - Name: "second-template", - Namespace: "ns2", + Kind: "ClusterRunTemplate", + Name: "second-template", } template, err := repo.GetRunTemplate(templateRef) Expect(err).ToNot(HaveOccurred()) Expect(template.GetName()).To(Equal("second-template")) }) - - It("finds nothing with a mismatched namespace", func() { - templateRef := v1alpha1.TemplateReference{ - Kind: "RunTemplate", - Name: "second-template", - Namespace: "ns1", - } - _, err := repo.GetRunTemplate(templateRef) - Expect(err).To(HaveOccurred()) - Expect(err.Error()).To(ContainSubstring("not found")) - }) }) Context("GetWorkload", func() { diff --git a/pkg/repository/repositoryfakes/fake_repository.go b/pkg/repository/repositoryfakes/fake_repository.go index 08f9f5b43..1eabe5e4e 100644 --- a/pkg/repository/repositoryfakes/fake_repository.go +++ b/pkg/repository/repositoryfakes/fake_repository.go @@ -78,17 +78,17 @@ type FakeRepository struct { result1 *v1alpha1.Pipeline result2 error } - GetRunTemplateStub func(v1alpha1.TemplateReference) (templates.RunTemplate, error) + GetRunTemplateStub func(v1alpha1.TemplateReference) (templates.ClusterRunTemplate, error) getRunTemplateMutex sync.RWMutex getRunTemplateArgsForCall []struct { arg1 v1alpha1.TemplateReference } getRunTemplateReturns struct { - result1 templates.RunTemplate + result1 templates.ClusterRunTemplate result2 error } getRunTemplateReturnsOnCall map[int]struct { - result1 templates.RunTemplate + result1 templates.ClusterRunTemplate result2 error } GetSchemeStub func() *runtime.Scheme @@ -488,7 +488,7 @@ func (fake *FakeRepository) GetPipelineReturnsOnCall(i int, result1 *v1alpha1.Pi }{result1, result2} } -func (fake *FakeRepository) GetRunTemplate(arg1 v1alpha1.TemplateReference) (templates.RunTemplate, error) { +func (fake *FakeRepository) GetRunTemplate(arg1 v1alpha1.TemplateReference) (templates.ClusterRunTemplate, error) { fake.getRunTemplateMutex.Lock() ret, specificReturn := fake.getRunTemplateReturnsOnCall[len(fake.getRunTemplateArgsForCall)] fake.getRunTemplateArgsForCall = append(fake.getRunTemplateArgsForCall, struct { @@ -513,7 +513,7 @@ func (fake *FakeRepository) GetRunTemplateCallCount() int { return len(fake.getRunTemplateArgsForCall) } -func (fake *FakeRepository) GetRunTemplateCalls(stub func(v1alpha1.TemplateReference) (templates.RunTemplate, error)) { +func (fake *FakeRepository) GetRunTemplateCalls(stub func(v1alpha1.TemplateReference) (templates.ClusterRunTemplate, error)) { fake.getRunTemplateMutex.Lock() defer fake.getRunTemplateMutex.Unlock() fake.GetRunTemplateStub = stub @@ -526,28 +526,28 @@ func (fake *FakeRepository) GetRunTemplateArgsForCall(i int) v1alpha1.TemplateRe return argsForCall.arg1 } -func (fake *FakeRepository) GetRunTemplateReturns(result1 templates.RunTemplate, result2 error) { +func (fake *FakeRepository) GetRunTemplateReturns(result1 templates.ClusterRunTemplate, result2 error) { fake.getRunTemplateMutex.Lock() defer fake.getRunTemplateMutex.Unlock() fake.GetRunTemplateStub = nil fake.getRunTemplateReturns = struct { - result1 templates.RunTemplate + result1 templates.ClusterRunTemplate result2 error }{result1, result2} } -func (fake *FakeRepository) GetRunTemplateReturnsOnCall(i int, result1 templates.RunTemplate, result2 error) { +func (fake *FakeRepository) GetRunTemplateReturnsOnCall(i int, result1 templates.ClusterRunTemplate, result2 error) { fake.getRunTemplateMutex.Lock() defer fake.getRunTemplateMutex.Unlock() fake.GetRunTemplateStub = nil if fake.getRunTemplateReturnsOnCall == nil { fake.getRunTemplateReturnsOnCall = make(map[int]struct { - result1 templates.RunTemplate + result1 templates.ClusterRunTemplate result2 error }) } fake.getRunTemplateReturnsOnCall[i] = struct { - result1 templates.RunTemplate + result1 templates.ClusterRunTemplate result2 error }{result1, result2} } diff --git a/pkg/templates/run_template.go b/pkg/templates/cluster_run_template.go similarity index 96% rename from pkg/templates/run_template.go rename to pkg/templates/cluster_run_template.go index a76ecac1c..78ecc1e08 100644 --- a/pkg/templates/run_template.go +++ b/pkg/templates/cluster_run_template.go @@ -28,14 +28,14 @@ import ( type Outputs map[string]apiextensionsv1.JSON -type RunTemplate interface { +type ClusterRunTemplate interface { GetName() string GetResourceTemplate() v1alpha1.TemplateSpec GetOutput(stampedObjects []*unstructured.Unstructured) (Outputs, error) } type runTemplate struct { - template *v1alpha1.RunTemplate + template *v1alpha1.ClusterRunTemplate } func (t runTemplate) GetOutput(stampedObjects []*unstructured.Unstructured) (Outputs, error) { @@ -130,7 +130,7 @@ func (t runTemplate) getOutputsOfSingleObject(evaluator eval.Evaluator, stampedO return objectErr, provisionalOutputs } -func NewRunTemplateModel(template *v1alpha1.RunTemplate) RunTemplate { +func NewRunTemplateModel(template *v1alpha1.ClusterRunTemplate) ClusterRunTemplate { return &runTemplate{template: template} } diff --git a/pkg/templates/run_template_test.go b/pkg/templates/cluster_run_template_test.go similarity index 98% rename from pkg/templates/run_template_test.go rename to pkg/templates/cluster_run_template_test.go index c11284b45..d6bd5f756 100644 --- a/pkg/templates/run_template_test.go +++ b/pkg/templates/cluster_run_template_test.go @@ -27,16 +27,16 @@ import ( "github.com/vmware-tanzu/cartographer/pkg/utils" ) -var _ = Describe("RunTemplate", func() { +var _ = Describe("ClusterRunTemplate", func() { Describe("GetOutput", func() { var ( - apiTemplate *v1alpha1.RunTemplate + apiTemplate *v1alpha1.ClusterRunTemplate firstStampedObject, secondStampedObject, unconditionedStampedObject *unstructured.Unstructured stampedObjects []*unstructured.Unstructured ) BeforeEach(func() { - apiTemplate = &v1alpha1.RunTemplate{} + apiTemplate = &v1alpha1.ClusterRunTemplate{} firstStampedObject = &unstructured.Unstructured{} firstStampedObjectManifest := utils.HereYamlF(` diff --git a/rfc/rfc-0013-delivery.md b/rfc/rfc-0013-delivery.md index d986563f3..ffe663809 100644 --- a/rfc/rfc-0013-delivery.md +++ b/rfc/rfc-0013-delivery.md @@ -467,7 +467,7 @@ spec: PipelineRun - Tests ```yaml apiVersion: carto.run/v1alpha1 -kind: RunTemplate +kind: ClusterRunTemplate metadata: name: default-tekton-source-provider spec: diff --git a/tests/integration/pipeline_service/pipeline_service_test.go b/tests/integration/pipeline_service/pipeline_service_test.go index 964670589..7a39a6f00 100644 --- a/tests/integration/pipeline_service/pipeline_service_test.go +++ b/tests/integration/pipeline_service/pipeline_service_test.go @@ -56,12 +56,12 @@ var _ = Describe("Stamping a resource on Pipeline Creation", func() { return *testStatusCondition, err } - Describe("when a RunTemplate that produces a Resource leverages a Pipeline field", func() { + Describe("when a ClusterRunTemplate that produces a Resource leverages a Pipeline field", func() { BeforeEach(func() { runTemplateYaml := HereYamlF(` --- apiVersion: carto.run/v1alpha1 - kind: RunTemplate + kind: ClusterRunTemplate metadata: namespace: %s name: my-run-template @@ -113,7 +113,7 @@ var _ = Describe("Stamping a resource on Pipeline Creation", func() { runTemplateRef: name: my-run-template namespace: %s - kind: RunTemplate + kind: ClusterRunTemplate inputs: key: val `, @@ -180,7 +180,7 @@ var _ = Describe("Stamping a resource on Pipeline Creation", func() { }) }) - Context("and the RunTemplate object is updated", func() { + Context("and the ClusterRunTemplate object is updated", func() { It("creates a second object alongside the first", func() { resourceList := &v1.ResourceQuotaList{} @@ -236,7 +236,7 @@ var _ = Describe("Stamping a resource on Pipeline Creation", func() { runTemplateRef: name: my-run-template-does-not-match namespace: %s - kind: RunTemplate + kind: ClusterRunTemplate `, testNS, testNS) @@ -264,12 +264,12 @@ var _ = Describe("Stamping a resource on Pipeline Creation", func() { }) }) - Describe("A RunTemplate that selects for outputs that are eventually available", func() { + Describe("A ClusterRunTemplate that selects for outputs that are eventually available", func() { BeforeEach(func() { runTemplateYaml := HereYamlF(` --- apiVersion: carto.run/v1alpha1 - kind: RunTemplate + kind: ClusterRunTemplate metadata: namespace: %s name: my-run-template @@ -306,7 +306,7 @@ var _ = Describe("Stamping a resource on Pipeline Creation", func() { runTemplateRef: name: my-run-template namespace: %s - kind: RunTemplate + kind: ClusterRunTemplate `, testNS, testNS) @@ -431,7 +431,7 @@ var _ = Describe("Stamping a resource on Pipeline Creation", func() { runTemplateRef: name: my-run-template namespace: %s - kind: RunTemplate + kind: ClusterRunTemplate `, testNS, testNS) @@ -445,7 +445,7 @@ var _ = Describe("Stamping a resource on Pipeline Creation", func() { runTemplateYaml := HereYamlF(` --- apiVersion: carto.run/v1alpha1 - kind: RunTemplate + kind: ClusterRunTemplate metadata: namespace: %s name: my-run-template diff --git a/tests/kuttl/pipeline-service/CRDs/00-assert.yaml b/tests/kuttl/pipeline-service/CRDs/00-assert.yaml index 45e520faf..c9ffba659 100644 --- a/tests/kuttl/pipeline-service/CRDs/00-assert.yaml +++ b/tests/kuttl/pipeline-service/CRDs/00-assert.yaml @@ -25,6 +25,6 @@ spec: apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: - name: runtemplates.carto.run + name: clusterruntemplates.carto.run spec: - scope: Namespaced + scope: Cluster diff --git a/tests/kuttl/pipeline-service/default/00-assert.yaml b/tests/kuttl/pipeline-service/default/00-assert.yaml index a9c228912..716fc584a 100644 --- a/tests/kuttl/pipeline-service/default/00-assert.yaml +++ b/tests/kuttl/pipeline-service/default/00-assert.yaml @@ -14,6 +14,6 @@ --- apiVersion: carto.run/v1alpha1 -kind: RunTemplate +kind: ClusterRunTemplate metadata: name: my-run-template diff --git a/tests/kuttl/pipeline-service/default/00-run-template.yaml b/tests/kuttl/pipeline-service/default/00-run-template.yaml index 01569b92b..0d9862705 100644 --- a/tests/kuttl/pipeline-service/default/00-run-template.yaml +++ b/tests/kuttl/pipeline-service/default/00-run-template.yaml @@ -14,7 +14,7 @@ --- apiVersion: carto.run/v1alpha1 -kind: RunTemplate +kind: ClusterRunTemplate metadata: name: my-run-template spec: diff --git a/tests/kuttl/pipeline-service/default/03-run-template.yaml b/tests/kuttl/pipeline-service/default/03-run-template.yaml index 5a2755d0d..5d53eb095 100644 --- a/tests/kuttl/pipeline-service/default/03-run-template.yaml +++ b/tests/kuttl/pipeline-service/default/03-run-template.yaml @@ -14,7 +14,7 @@ --- apiVersion: carto.run/v1alpha1 -kind: RunTemplate +kind: ClusterRunTemplate metadata: name: my-run-template spec: diff --git a/tests/kuttl/pipeline-service/multi-label-selector/00-run-template.yaml b/tests/kuttl/pipeline-service/multi-label-selector/00-run-template.yaml index e8a6295cf..cdddacb16 100644 --- a/tests/kuttl/pipeline-service/multi-label-selector/00-run-template.yaml +++ b/tests/kuttl/pipeline-service/multi-label-selector/00-run-template.yaml @@ -14,7 +14,7 @@ --- apiVersion: carto.run/v1alpha1 -kind: RunTemplate +kind: ClusterRunTemplate metadata: name: run-template---multi-label-selector spec: diff --git a/tests/kuttl/pipeline-service/pipeline-with-inputs/00-run-template.yaml b/tests/kuttl/pipeline-service/pipeline-with-inputs/00-run-template.yaml index 4de34a9b7..9367f2f02 100644 --- a/tests/kuttl/pipeline-service/pipeline-with-inputs/00-run-template.yaml +++ b/tests/kuttl/pipeline-service/pipeline-with-inputs/00-run-template.yaml @@ -14,7 +14,7 @@ --- apiVersion: carto.run/v1alpha1 -kind: RunTemplate +kind: ClusterRunTemplate metadata: name: my-run-template-inputs spec: diff --git a/tests/kuttl/pipeline-service/pipelines-by-label-selector/00-run-template.yaml b/tests/kuttl/pipeline-service/pipelines-by-label-selector/00-run-template.yaml index 84ef49b00..adc3f5138 100644 --- a/tests/kuttl/pipeline-service/pipelines-by-label-selector/00-run-template.yaml +++ b/tests/kuttl/pipeline-service/pipelines-by-label-selector/00-run-template.yaml @@ -14,7 +14,7 @@ --- apiVersion: carto.run/v1alpha1 -kind: RunTemplate +kind: ClusterRunTemplate metadata: name: run-template---pipelines-by-label-selector spec: diff --git a/tests/kuttl/pipeline-service/pipelines-driven-by-supply-chain/00-run-template.yaml b/tests/kuttl/pipeline-service/pipelines-driven-by-supply-chain/00-run-template.yaml index 1336e4961..7153d1246 100644 --- a/tests/kuttl/pipeline-service/pipelines-driven-by-supply-chain/00-run-template.yaml +++ b/tests/kuttl/pipeline-service/pipelines-driven-by-supply-chain/00-run-template.yaml @@ -14,9 +14,9 @@ --- apiVersion: carto.run/v1alpha1 -kind: RunTemplate +kind: ClusterRunTemplate metadata: - name: my-run-template-inputs + name: my-run-template-driven-by-supply-chain spec: template: apiVersion: test.run/v1alpha1 diff --git a/tests/kuttl/pipeline-service/pipelines-driven-by-supply-chain/00-templates.yaml b/tests/kuttl/pipeline-service/pipelines-driven-by-supply-chain/00-templates.yaml index 11d286c8c..7804c2e50 100644 --- a/tests/kuttl/pipeline-service/pipelines-driven-by-supply-chain/00-templates.yaml +++ b/tests/kuttl/pipeline-service/pipelines-driven-by-supply-chain/00-templates.yaml @@ -53,7 +53,7 @@ spec: my-label: this-is-it spec: runTemplateRef: - name: my-run-template-inputs + name: my-run-template-driven-by-supply-chain inputs: source-url: $(source.url)$