diff --git a/PROJECT b/PROJECT index 6acac99..c2e4e10 100644 --- a/PROJECT +++ b/PROJECT @@ -25,4 +25,12 @@ resources: kind: Project path: github.com/konflux-ci/project-controller/api/v1beta1 version: v1beta1 +- api: + crdVersion: v1 + namespaced: true + domain: konflux.dev + group: projctl + kind: ProjectDevelopmentStreamTemplate + path: github.com/konflux-ci/project-controller/api/v1beta1 + version: v1beta1 version: "3" diff --git a/api/v1beta1/projectdevelopmentstreamtemplate_types.go b/api/v1beta1/projectdevelopmentstreamtemplate_types.go new file mode 100644 index 0000000..04f26a7 --- /dev/null +++ b/api/v1beta1/projectdevelopmentstreamtemplate_types.go @@ -0,0 +1,75 @@ +/* +Copyright 2024. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package v1beta1 + +import ( + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" +) + +// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN! +// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized. + +// Settings for a variable to be used to customize the template results +type ProjectDevelopmentStreamTemplateVariable struct { + // Variable name + Name string `json:"name"` + // Optional default value for use when a value for the variable is not given + // can reference values of other previously defined variables using the Go + // text/template syntax + Default *string `json:"default,omitempty"` + // Optional description for the variable for display in the UI + Description string `json:"description,omitempty"` +} + +// ProjectDevelopmentStreamTemplateSpec defines the resources to be generated +// using a ProjectDevelopmentStreamTemplate +type ProjectDevelopmentStreamTemplateSpec struct { + // The name of the project this stream template belongs to + Project string `json:"project,omitempty"` + // List of variables to allow customizing the template results. The order + // variables in the list is significant as earlier variables can be + // referenced by the default values for later variables + Variables []ProjectDevelopmentStreamTemplateVariable `json:"variables,omitempty"` + // List of resources to be created for version made from this template + // certain values for resource properties may include references to + // variables using the Go-text/template syntax + Resources []UnstructuredObj `json:"resources,omitempty"` +} + +//+kubebuilder:object:root=true +//+kubebuilder:subresource:status + +// ProjectDevelopmentStreamTemplate is the Schema for the projectdevelopmentstreamtemplates API +type ProjectDevelopmentStreamTemplate struct { + metav1.TypeMeta `json:",inline"` + metav1.ObjectMeta `json:"metadata,omitempty"` + + Spec ProjectDevelopmentStreamTemplateSpec `json:"spec,omitempty"` +} + +//+kubebuilder:object:root=true + +// ProjectDevelopmentStreamTemplateList contains a list of ProjectDevelopmentStreamTemplate +type ProjectDevelopmentStreamTemplateList struct { + metav1.TypeMeta `json:",inline"` + metav1.ListMeta `json:"metadata,omitempty"` + Items []ProjectDevelopmentStreamTemplate `json:"items"` +} + +func init() { + SchemeBuilder.Register(&ProjectDevelopmentStreamTemplate{}, &ProjectDevelopmentStreamTemplateList{}) +} diff --git a/api/v1beta1/zz_generated.deepcopy.go b/api/v1beta1/zz_generated.deepcopy.go index 9142b9a..41658ed 100644 --- a/api/v1beta1/zz_generated.deepcopy.go +++ b/api/v1beta1/zz_generated.deepcopy.go @@ -146,6 +146,113 @@ func (in *ProjectDevelopmentStreamStatus) DeepCopy() *ProjectDevelopmentStreamSt return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *ProjectDevelopmentStreamTemplate) DeepCopyInto(out *ProjectDevelopmentStreamTemplate) { + *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 ProjectDevelopmentStreamTemplate. +func (in *ProjectDevelopmentStreamTemplate) DeepCopy() *ProjectDevelopmentStreamTemplate { + if in == nil { + return nil + } + out := new(ProjectDevelopmentStreamTemplate) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *ProjectDevelopmentStreamTemplate) 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 *ProjectDevelopmentStreamTemplateList) DeepCopyInto(out *ProjectDevelopmentStreamTemplateList) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ListMeta.DeepCopyInto(&out.ListMeta) + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]ProjectDevelopmentStreamTemplate, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ProjectDevelopmentStreamTemplateList. +func (in *ProjectDevelopmentStreamTemplateList) DeepCopy() *ProjectDevelopmentStreamTemplateList { + if in == nil { + return nil + } + out := new(ProjectDevelopmentStreamTemplateList) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *ProjectDevelopmentStreamTemplateList) 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 *ProjectDevelopmentStreamTemplateSpec) DeepCopyInto(out *ProjectDevelopmentStreamTemplateSpec) { + *out = *in + if in.Variables != nil { + in, out := &in.Variables, &out.Variables + *out = make([]ProjectDevelopmentStreamTemplateVariable, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } + if in.Resources != nil { + in, out := &in.Resources, &out.Resources + *out = make([]UnstructuredObj, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ProjectDevelopmentStreamTemplateSpec. +func (in *ProjectDevelopmentStreamTemplateSpec) DeepCopy() *ProjectDevelopmentStreamTemplateSpec { + if in == nil { + return nil + } + out := new(ProjectDevelopmentStreamTemplateSpec) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *ProjectDevelopmentStreamTemplateVariable) DeepCopyInto(out *ProjectDevelopmentStreamTemplateVariable) { + *out = *in + if in.Default != nil { + in, out := &in.Default, &out.Default + *out = new(string) + **out = **in + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ProjectDevelopmentStreamTemplateVariable. +func (in *ProjectDevelopmentStreamTemplateVariable) DeepCopy() *ProjectDevelopmentStreamTemplateVariable { + if in == nil { + return nil + } + out := new(ProjectDevelopmentStreamTemplateVariable) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *ProjectList) DeepCopyInto(out *ProjectList) { *out = *in diff --git a/config/crd/bases/projctl.konflux.dev_projectdevelopmentstreamtemplates.yaml b/config/crd/bases/projctl.konflux.dev_projectdevelopmentstreamtemplates.yaml new file mode 100644 index 0000000..ecf75c7 --- /dev/null +++ b/config/crd/bases/projctl.konflux.dev_projectdevelopmentstreamtemplates.yaml @@ -0,0 +1,89 @@ +--- +apiVersion: apiextensions.k8s.io/v1 +kind: CustomResourceDefinition +metadata: + annotations: + controller-gen.kubebuilder.io/version: v0.14.0 + name: projectdevelopmentstreamtemplates.projctl.konflux.dev +spec: + group: projctl.konflux.dev + names: + kind: ProjectDevelopmentStreamTemplate + listKind: ProjectDevelopmentStreamTemplateList + plural: projectdevelopmentstreamtemplates + singular: projectdevelopmentstreamtemplate + scope: Namespaced + versions: + - name: v1beta1 + schema: + openAPIV3Schema: + description: ProjectDevelopmentStreamTemplate is the Schema for the projectdevelopmentstreamtemplates + API + properties: + apiVersion: + description: |- + APIVersion defines the versioned schema of this representation of an object. + Servers should convert recognized schemas to the latest internal value, and + may reject unrecognized values. + More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources + type: string + kind: + description: |- + Kind is a string value representing the REST resource this object represents. + Servers may infer this from the endpoint the client submits requests to. + Cannot be updated. + In CamelCase. + More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds + type: string + metadata: + type: object + spec: + description: |- + ProjectDevelopmentStreamTemplateSpec defines the resources to be generated + using a ProjectDevelopmentStreamTemplate + properties: + project: + description: The name of the project this stream template belongs + to + type: string + resources: + description: |- + List of resources to be created for version made from this template + certain values for resource properties may include references to + variables using the Go-text/template syntax + items: + type: object + x-kubernetes-preserve-unknown-fields: true + type: array + variables: + description: |- + List of variables to allow customizing the template results. The order + variables in the list is significant as earlier variables can be + referenced by the default values for later variables + items: + description: Settings for a variable to be used to customize the + template results + properties: + default: + description: |- + Optional default value for use when a value for the variable is not given + can reference values of other previously defined variables using the Go + text/template syntax + type: string + description: + description: Optional description for the variable for display + in the UI + type: string + name: + description: Variable name + type: string + required: + - name + type: object + type: array + type: object + type: object + served: true + storage: true + subresources: + status: {} diff --git a/config/crd/kustomization.yaml b/config/crd/kustomization.yaml index 7bf8715..df10435 100644 --- a/config/crd/kustomization.yaml +++ b/config/crd/kustomization.yaml @@ -4,6 +4,7 @@ resources: - bases/projctl.konflux.dev_projectdevelopmentstreams.yaml - bases/projctl.konflux.dev_projects.yaml +- bases/projctl.konflux.dev_projectdevelopmentstreamtemplates.yaml #+kubebuilder:scaffold:crdkustomizeresource patches: @@ -11,12 +12,14 @@ patches: # patches here are for enabling the conversion webhook for each CRD #- path: patches/webhook_in_projectdevelopmentstreams.yaml #- path: patches/webhook_in_projects.yaml +#- path: patches/webhook_in_projectdevelopmentstreamtemplates.yaml #+kubebuilder:scaffold:crdkustomizewebhookpatch # [CERTMANAGER] To enable cert-manager, uncomment all the sections with [CERTMANAGER] prefix. # patches here are for enabling the CA injection for each CRD #- path: patches/cainjection_in_projectdevelopmentstreams.yaml #- path: patches/cainjection_in_projects.yaml +#- path: patches/cainjection_in_projectdevelopmentstreamtemplates.yaml #+kubebuilder:scaffold:crdkustomizecainjectionpatch # [WEBHOOK] To enable webhook, uncomment the following section diff --git a/config/rbac/projectdevelopmentstreamtemplate_editor_role.yaml b/config/rbac/projectdevelopmentstreamtemplate_editor_role.yaml new file mode 100644 index 0000000..ca5a35a --- /dev/null +++ b/config/rbac/projectdevelopmentstreamtemplate_editor_role.yaml @@ -0,0 +1,31 @@ +# permissions for end users to edit projectdevelopmentstreamtemplates. +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRole +metadata: + labels: + app.kubernetes.io/name: clusterrole + app.kubernetes.io/instance: projectdevelopmentstreamtemplate-editor-role + app.kubernetes.io/component: rbac + app.kubernetes.io/created-by: project-controller + app.kubernetes.io/part-of: project-controller + app.kubernetes.io/managed-by: kustomize + name: projectdevelopmentstreamtemplate-editor-role +rules: +- apiGroups: + - projctl.konflux.dev + resources: + - projectdevelopmentstreamtemplates + verbs: + - create + - delete + - get + - list + - patch + - update + - watch +- apiGroups: + - projctl.konflux.dev + resources: + - projectdevelopmentstreamtemplates/status + verbs: + - get diff --git a/config/rbac/projectdevelopmentstreamtemplate_viewer_role.yaml b/config/rbac/projectdevelopmentstreamtemplate_viewer_role.yaml new file mode 100644 index 0000000..bd5204c --- /dev/null +++ b/config/rbac/projectdevelopmentstreamtemplate_viewer_role.yaml @@ -0,0 +1,27 @@ +# permissions for end users to view projectdevelopmentstreamtemplates. +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRole +metadata: + labels: + app.kubernetes.io/name: clusterrole + app.kubernetes.io/instance: projectdevelopmentstreamtemplate-viewer-role + app.kubernetes.io/component: rbac + app.kubernetes.io/created-by: project-controller + app.kubernetes.io/part-of: project-controller + app.kubernetes.io/managed-by: kustomize + name: projectdevelopmentstreamtemplate-viewer-role +rules: +- apiGroups: + - projctl.konflux.dev + resources: + - projectdevelopmentstreamtemplates + verbs: + - get + - list + - watch +- apiGroups: + - projctl.konflux.dev + resources: + - projectdevelopmentstreamtemplates/status + verbs: + - get diff --git a/config/samples/kustomization.yaml b/config/samples/kustomization.yaml index 780bb5a..962abe8 100644 --- a/config/samples/kustomization.yaml +++ b/config/samples/kustomization.yaml @@ -2,4 +2,5 @@ resources: - projctl_v1beta1_projectdevelopmentstream.yaml - projctl_v1beta1_project.yaml +- projctl_v1beta1_projectdevelopmentstreamtemplate.yaml #+kubebuilder:scaffold:manifestskustomizesamples diff --git a/config/samples/projctl_v1beta1_projectdevelopmentstreamtemplate.yaml b/config/samples/projctl_v1beta1_projectdevelopmentstreamtemplate.yaml new file mode 100644 index 0000000..5b13254 --- /dev/null +++ b/config/samples/projctl_v1beta1_projectdevelopmentstreamtemplate.yaml @@ -0,0 +1,77 @@ +apiVersion: projctl.konflux.dev/v1beta1 +kind: ProjectDevelopmentStreamTemplate +metadata: + labels: + app.kubernetes.io/name: projectdevelopmentstreamtemplate + app.kubernetes.io/instance: projectdevelopmentstreamtemplate-sample + app.kubernetes.io/part-of: project-controller + app.kubernetes.io/managed-by: kustomize + app.kubernetes.io/created-by: project-controller + name: projectdevelopmentstreamtemplate-sample +spec: + project: project-sample + variables: + - name: version + description: A version number for the new development stream + + - name: cool-comp1-context + defaultValue: ./ + description: Context directory for cool-comp1 component + - name: cool-comp1-dockerfileUrl + defaultValue: Dockerfile + description: Dockerfile location for cool-comp1 component + - name: cool-comp1-revision + defaultValue: "{version}" + description: Git revision for cool-comp1 component + + - name: cool-comp2-context + defaultValue: ./ + description: Context directory for cool-comp2 component + - name: cool-comp2-dockerfileUrl + defaultValue: Dockerfile + description: Dockerfile location for cool-comp2 component + - name: cool-comp2-revision + defaultValue: fixed-rev + description: Git revision for cool-comp2 component + + resources: + - apiVersion: appstudio.redhat.com/v1alpha1 + kind: Application + metadata: + name: "cool-app-{version}" + annotations: + pvc.konflux.dev/cloned-from: cool-app1-main + spec: + displayName: "Cool App {version}" + + - apiVersion: appstudio.redhat.com/v1alpha1 + kind: Component + metadata: + name: "cool-comp1-{version}" + annotations: + pvc.konflux.dev/cloned-from: cool-comp1-main + spec: + application: "cool-app-{version}" + componentName: "cool-comp1-{version}" + source: + git: + context: "{cool-comp1-context}" + dockerfileUrl: "{cool-comp1-dockerfileUrl}" + revision: "{cool-comp1-revision}" + uri: git@github.com:example/comp1.git + + - apiVersion: appstudio.redhat.com/v1alpha1 + kind: Component + metadata: + name: "cool-comp2-{version}" + annotations: + pvc.konflux.dev/cloned-from: cool-comp2-main + spec: + application: "cool-app-{version}" + componentName: "cool-comp2-{version}" + source: + git: + context: "{cool-comp2-context}" + dockerfileUrl: "{cool-comp2-dockerfileUrl}" + revision: "{cool-comp2-revision}" + uri: git@github.com:example/comp2.git