Skip to content

Commit

Permalink
Merge pull request #246 from vmware-tanzu/197-cluster-scope-runtemplates
Browse files Browse the repository at this point in the history
Move runtemplate from ns scoped to cluster scoped, rename
  • Loading branch information
Ciro S. Costa authored Oct 19, 2021
2 parents a90f8c8 + c0737a9 commit 1de5584
Show file tree
Hide file tree
Showing 30 changed files with 179 additions and 250 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 0 additions & 2 deletions config/crd/bases/carto.run_pipelines.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,6 @@ spec:
name:
minLength: 1
type: string
namespace:
type: string
required:
- name
type: object
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,30 +24,31 @@ 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"`
}

// +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{},
)
}
3 changes: 1 addition & 2 deletions pkg/apis/v1alpha1/pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 0 additions & 8 deletions pkg/apis/v1alpha1/pipeline_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
})
})
})
162 changes: 81 additions & 81 deletions pkg/apis/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions pkg/controller/pipeline/reconciler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion pkg/realizer/pipeline/conditions.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"github.com/vmware-tanzu/cartographer/pkg/apis/v1alpha1"
)

// -- RunTemplate conditions
// -- ClusterRunTemplate conditions

func RunTemplateReadyCondition() *metav1.Condition {
return &metav1.Condition{
Expand Down
13 changes: 4 additions & 9 deletions pkg/realizer/pipeline/realizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading

0 comments on commit 1de5584

Please sign in to comment.