diff --git a/PROJECT b/PROJECT index dacd1dfdf..c62f7fb53 100644 --- a/PROJECT +++ b/PROJECT @@ -18,8 +18,7 @@ resources: path: k8s.io/api/core/v1 version: v1 - api: - crdVersion: v1alpha1 - namespaced: false + crdVersion: v1 controller: true domain: openshift.io group: multiarch @@ -30,8 +29,7 @@ resources: conversion: true webhookVersion: v1 - api: - crdVersion: v1beta1 - namespaced: false + crdVersion: v1 domain: openshift.io group: multiarch kind: ClusterPodPlacementConfig @@ -40,4 +38,13 @@ resources: webhooks: conversion: true webhookVersion: v1 +- api: + crdVersion: v1 + namespaced: true + controller: true + domain: openshift.io + group: multiarch + kind: ENoExecEvent + path: github.com/openshift/multiarch-tuning-operator/apis/multiarch/v1beta1 + version: v1beta1 version: "3" diff --git a/apis/multiarch/v1beta1/enoexecevent_types.go b/apis/multiarch/v1beta1/enoexecevent_types.go new file mode 100644 index 000000000..14a33feeb --- /dev/null +++ b/apis/multiarch/v1beta1/enoexecevent_types.go @@ -0,0 +1,64 @@ +/* +Copyright 2023 Red Hat, Inc. + +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. + +// ENoExecEventSpec defines the desired state of ENoExecEvent +type ENoExecEventSpec struct { + // INSERT ADDITIONAL SPEC FIELDS - desired state of cluster + // Important: Run "make" to regenerate code after modifying this file + + // Foo is an example field of ENoExecEvent. Edit enoexecevent_types.go to remove/update + Foo string `json:"foo,omitempty"` +} + +// ENoExecEventStatus defines the observed state of ENoExecEvent +type ENoExecEventStatus struct { + // INSERT ADDITIONAL STATUS FIELD - define observed state of cluster + // Important: Run "make" to regenerate code after modifying this file +} + +//+kubebuilder:object:root=true +//+kubebuilder:subresource:status + +// ENoExecEvent is the Schema for the enoexecevents API +type ENoExecEvent struct { + metav1.TypeMeta `json:",inline"` + metav1.ObjectMeta `json:"metadata,omitempty"` + + Spec ENoExecEventSpec `json:"spec,omitempty"` + Status ENoExecEventStatus `json:"status,omitempty"` +} + +//+kubebuilder:object:root=true + +// ENoExecEventList contains a list of ENoExecEvent +type ENoExecEventList struct { + metav1.TypeMeta `json:",inline"` + metav1.ListMeta `json:"metadata,omitempty"` + Items []ENoExecEvent `json:"items"` +} + +func init() { + SchemeBuilder.Register(&ENoExecEvent{}, &ENoExecEventList{}) +} diff --git a/apis/multiarch/v1beta1/zz_generated.deepcopy.go b/apis/multiarch/v1beta1/zz_generated.deepcopy.go index 3fbe70653..00eb4d7fe 100644 --- a/apis/multiarch/v1beta1/zz_generated.deepcopy.go +++ b/apis/multiarch/v1beta1/zz_generated.deepcopy.go @@ -146,3 +146,92 @@ func (in *ClusterPodPlacementConfigValidator) DeepCopy() *ClusterPodPlacementCon in.DeepCopyInto(out) return out } + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *ENoExecEvent) DeepCopyInto(out *ENoExecEvent) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) + out.Spec = in.Spec + out.Status = in.Status +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ENoExecEvent. +func (in *ENoExecEvent) DeepCopy() *ENoExecEvent { + if in == nil { + return nil + } + out := new(ENoExecEvent) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *ENoExecEvent) 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 *ENoExecEventList) DeepCopyInto(out *ENoExecEventList) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ListMeta.DeepCopyInto(&out.ListMeta) + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]ENoExecEvent, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ENoExecEventList. +func (in *ENoExecEventList) DeepCopy() *ENoExecEventList { + if in == nil { + return nil + } + out := new(ENoExecEventList) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *ENoExecEventList) 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 *ENoExecEventSpec) DeepCopyInto(out *ENoExecEventSpec) { + *out = *in +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ENoExecEventSpec. +func (in *ENoExecEventSpec) DeepCopy() *ENoExecEventSpec { + if in == nil { + return nil + } + out := new(ENoExecEventSpec) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *ENoExecEventStatus) DeepCopyInto(out *ENoExecEventStatus) { + *out = *in +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ENoExecEventStatus. +func (in *ENoExecEventStatus) DeepCopy() *ENoExecEventStatus { + if in == nil { + return nil + } + out := new(ENoExecEventStatus) + in.DeepCopyInto(out) + return out +} diff --git a/bundle.Dockerfile b/bundle.Dockerfile index d86d8f3b5..a3b7794da 100644 --- a/bundle.Dockerfile +++ b/bundle.Dockerfile @@ -19,23 +19,3 @@ LABEL operators.operatorframework.io.test.config.v1=tests/scorecard/ COPY bundle/manifests /manifests/ COPY bundle/metadata /metadata/ COPY bundle/tests/scorecard /tests/scorecard/ - -# Labels from hack/patch-bundle-dockerfile.sh -LABEL com.redhat.component="Multiarch Tuning Operator" -LABEL distribution-scope="public" -LABEL name="multiarch-tuning-operator-bundle" -LABEL release="1.1.1" -LABEL version="1.1.1" -LABEL url="https://github.com/openshift/multiarch-tuning-operator" -LABEL vendor="Red Hat, Inc." -LABEL description="The Multiarch Tuning Operator enhances the user experience for administrators of Openshift \ - clusters with multi-architecture compute nodes or Site Reliability Engineers willing to \ - migrate from single-arch to multi-arch OpenShift" -LABEL io.k8s.description="The Multiarch Tuning Operator enhances the user experience for administrators of Openshift \ - clusters with multi-architecture compute nodes or Site Reliability Engineers willing to \ - migrate from single-arch to multi-arch OpenShift" -LABEL summary="The Multiarch Tuning Operator enhances the user experience for administrators of Openshift \ - clusters with multi-architecture compute nodes or Site Reliability Engineers willing to \ - migrate from single-arch to multi-arch OpenShift" -LABEL io.k8s.display-name="Multiarch Tuning Operator" -LABEL io.openshift.tags="openshift,operator,multiarch,scheduling" diff --git a/bundle/manifests/multiarch-tuning-operator.clusterserviceversion.yaml b/bundle/manifests/multiarch-tuning-operator.clusterserviceversion.yaml index 78b6e0c97..74056301b 100644 --- a/bundle/manifests/multiarch-tuning-operator.clusterserviceversion.yaml +++ b/bundle/manifests/multiarch-tuning-operator.clusterserviceversion.yaml @@ -2,32 +2,12 @@ apiVersion: operators.coreos.com/v1alpha1 kind: ClusterServiceVersion metadata: annotations: - alm-examples: |- - [ - { - "apiVersion": "multiarch.openshift.io/v1beta1", - "kind": "ClusterPodPlacementConfig", - "metadata": { - "name": "cluster" - }, - "spec": { - "logVerbosity": "Normal", - "namespaceSelector": { - "matchExpressions": [ - { - "key": "multiarch.openshift.io/exclude-pod-placement", - "operator": "DoesNotExist" - } - ] - } - } - } - ] + alm-examples: '[]' capabilities: Seamless Upgrades categories: OpenShift Optional, Other console.openshift.io/disable-operand-delete: "false" containerImage: registry.ci.openshift.org/origin/multiarch-tuning-operator:main - createdAt: "2025-05-07T19:54:50Z" + createdAt: "2025-05-29T09:18:52Z" features.operators.openshift.io/cnf: "false" features.operators.openshift.io/cni: "false" features.operators.openshift.io/csi: "false" @@ -57,22 +37,7 @@ metadata: namespace: openshift-multiarch-tuning-operator spec: apiservicedefinitions: {} - customresourcedefinitions: - owned: - - description: ClusterPodPlacementConfig defines the configuration for the architecture - aware pod placement operand. Users can only deploy a single object named "cluster". - Creating the object enables the operand. - displayName: Cluster Pod Placement Config - kind: ClusterPodPlacementConfig - name: clusterpodplacementconfigs.multiarch.openshift.io - version: v1alpha1 - - description: ClusterPodPlacementConfig defines the configuration for the architecture - aware pod placement operand. Users can only deploy a single object named "cluster". - Creating the object enables the operand. - displayName: Cluster Pod Placement Config - kind: ClusterPodPlacementConfig - name: clusterpodplacementconfigs.multiarch.openshift.io - version: v1beta1 + customresourcedefinitions: {} description: | The Multiarch Tuning Operator optimizes workload management within multi-architecture clusters and in single-architecture clusters transitioning to multi-architecture environments. @@ -94,351 +59,7 @@ spec: mediatype: image/png install: spec: - clusterPermissions: - - rules: - - apiGroups: - - "" - resources: - - configmaps - - secrets - verbs: - - get - - list - - watch - - apiGroups: - - "" - resources: - - events - verbs: - - create - - patch - - apiGroups: - - "" - resources: - - namespaces - verbs: - - get - - update - - apiGroups: - - "" - resources: - - pods - verbs: - - get - - list - - patch - - update - - watch - - apiGroups: - - "" - resources: - - pods/status - verbs: - - get - - patch - - update - - apiGroups: - - "" - resources: - - serviceaccounts - - services - verbs: - - create - - delete - - get - - list - - patch - - update - - watch - - apiGroups: - - "" - resources: - - serviceaccounts/finalizers - verbs: - - update - - apiGroups: - - "" - resources: - - serviceaccounts/status - - services/status - verbs: - - get - - apiGroups: - - admissionregistration.k8s.io - resources: - - mutatingwebhookconfigurations - verbs: - - create - - delete - - get - - list - - patch - - update - - watch - - apiGroups: - - admissionregistration.k8s.io - resources: - - mutatingwebhookconfigurations/status - verbs: - - get - - apiGroups: - - apps - resources: - - deployments - verbs: - - create - - delete - - get - - list - - patch - - update - - watch - - apiGroups: - - apps - resources: - - deployments/finalizers - verbs: - - update - - apiGroups: - - apps - resources: - - deployments/status - verbs: - - get - - apiGroups: - - monitoring.coreos.com - resources: - - prometheusrules - - servicemonitors - verbs: - - create - - delete - - get - - list - - patch - - update - - watch - - apiGroups: - - multiarch.openshift.io - resources: - - clusterpodplacementconfigs - verbs: - - create - - delete - - get - - list - - patch - - update - - watch - - apiGroups: - - multiarch.openshift.io - resources: - - clusterpodplacementconfigs/finalizers - verbs: - - update - - apiGroups: - - multiarch.openshift.io - resources: - - clusterpodplacementconfigs/status - verbs: - - get - - patch - - update - - apiGroups: - - rbac.authorization.k8s.io - resources: - - clusterrolebindings - - clusterroles - - rolebindings - - roles - verbs: - - create - - delete - - get - - list - - patch - - update - - watch - - apiGroups: - - rbac.authorization.k8s.io - resources: - - clusterrolebindings/finalizers - - clusterroles/finalizers - - rolebindings/finalizers - - roles/finalizers - verbs: - - update - - apiGroups: - - rbac.authorization.k8s.io - resources: - - clusterrolebindings/status - - clusterroles/status - - rolebindings/status - - roles/status - verbs: - - get - - apiGroups: - - security.openshift.io - resources: - - securitycontextconstraints - verbs: - - use - - apiGroups: - - authentication.k8s.io - resources: - - tokenreviews - verbs: - - create - - apiGroups: - - authorization.k8s.io - resources: - - subjectaccessreviews - verbs: - - create - serviceAccountName: multiarch-tuning-operator-controller-manager - deployments: - - label: - app.kubernetes.io/component: manager - app.kubernetes.io/created-by: multiarch-tuning-operator - app.kubernetes.io/instance: controller-manager - app.kubernetes.io/managed-by: kustomize - app.kubernetes.io/name: deployment - app.kubernetes.io/part-of: multiarch-tuning-operator - control-plane: controller-manager - name: multiarch-tuning-operator-controller-manager - spec: - replicas: 2 - selector: - matchLabels: - control-plane: controller-manager - strategy: {} - template: - metadata: - annotations: - kubectl.kubernetes.io/default-container: manager - multiarch.openshift.io/image: registry.ci.openshift.org/origin/multiarch-tuning-operator:main - openshift.io/required-scc: restricted-v2 - target.workload.openshift.io/management: | - {"effect": "PreferredDuringScheduling"} - labels: - control-plane: controller-manager - spec: - affinity: - nodeAffinity: - requiredDuringSchedulingIgnoredDuringExecution: - nodeSelectorTerms: - - matchExpressions: - - key: kubernetes.io/arch - operator: In - values: - - amd64 - - arm64 - - ppc64le - - s390x - - key: kubernetes.io/os - operator: In - values: - - linux - automountServiceAccountToken: true - containers: - - args: - - --health-probe-bind-address=:8081 - - --metrics-bind-address=:8443 - - --leader-elect - - --enable-operator - command: - - /manager - env: - - name: NAMESPACE - valueFrom: - fieldRef: - fieldPath: metadata.namespace - - name: IMAGE - valueFrom: - fieldRef: - fieldPath: metadata.annotations['multiarch.openshift.io/image'] - image: registry.ci.openshift.org/origin/multiarch-tuning-operator:main - imagePullPolicy: Always - livenessProbe: - httpGet: - path: /healthz - port: 8081 - initialDelaySeconds: 15 - periodSeconds: 20 - name: manager - ports: - - containerPort: 8081 - name: health - protocol: TCP - - containerPort: 8443 - name: https - protocol: TCP - readinessProbe: - httpGet: - path: /readyz - port: 8081 - initialDelaySeconds: 5 - periodSeconds: 10 - resources: - requests: - cpu: 10m - memory: 64Mi - securityContext: - allowPrivilegeEscalation: false - capabilities: - drop: - - ALL - privileged: false - readOnlyRootFilesystem: true - runAsNonRoot: true - volumeMounts: - - mountPath: /var/run/manager/tls - name: multiarch-tuning-operator-controller-manager-service-cert - readOnly: true - priorityClassName: system-cluster-critical - securityContext: - runAsNonRoot: true - serviceAccountName: multiarch-tuning-operator-controller-manager - terminationGracePeriodSeconds: 10 - volumes: - - name: multiarch-tuning-operator-controller-manager-service-cert - secret: - defaultMode: 420 - secretName: multiarch-tuning-operator-controller-manager-service-cert - permissions: - - rules: - - apiGroups: - - "" - resources: - - configmaps - verbs: - - get - - list - - watch - - create - - update - - patch - - delete - - apiGroups: - - coordination.k8s.io - resources: - - leases - verbs: - - get - - list - - watch - - create - - update - - patch - - delete - - apiGroups: - - "" - resources: - - events - verbs: - - create - - patch - serviceAccountName: multiarch-tuning-operator-controller-manager + deployments: [] strategy: deployment installModes: - supported: false @@ -464,35 +85,3 @@ spec: name: Red Hat url: https://github.com/openshift/multiarch-tuning-operator version: 1.1.1 - webhookdefinitions: - - admissionReviewVersions: - - v1 - containerPort: 443 - conversionCRDs: - - clusterpodplacementconfigs.multiarch.openshift.io - deploymentName: multiarch-tuning-operator-controller-manager - generateName: cclusterpodplacementconfigs.kb.io - sideEffects: None - targetPort: 9443 - type: ConversionWebhook - webhookPath: /convert - - admissionReviewVersions: - - v1 - containerPort: 443 - deploymentName: multiarch-tuning-operator-controller-manager - failurePolicy: Fail - generateName: validate-clusterpodplacementconfig.multiarch.openshift.io - rules: - - apiGroups: - - multiarch.openshift.io - apiVersions: - - v1beta1 - operations: - - CREATE - - UPDATE - resources: - - clusterpodplacementconfigs - sideEffects: None - targetPort: 9443 - type: ValidatingAdmissionWebhook - webhookPath: /validate-multiarch-openshift-io-v1beta1-clusterpodplacementconfig diff --git a/config/crd/bases/multiarch.openshift.io_enoexecevents.yaml b/config/crd/bases/multiarch.openshift.io_enoexecevents.yaml new file mode 100644 index 000000000..3fefc1937 --- /dev/null +++ b/config/crd/bases/multiarch.openshift.io_enoexecevents.yaml @@ -0,0 +1,54 @@ +--- +apiVersion: apiextensions.k8s.io/v1 +kind: CustomResourceDefinition +metadata: + annotations: + controller-gen.kubebuilder.io/version: v0.17.2 + name: enoexecevents.multiarch.openshift.io +spec: + group: multiarch.openshift.io + names: + kind: ENoExecEvent + listKind: ENoExecEventList + plural: enoexecevents + singular: enoexecevent + scope: Namespaced + versions: + - name: v1beta1 + schema: + openAPIV3Schema: + description: ENoExecEvent is the Schema for the enoexecevents 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: ENoExecEventSpec defines the desired state of ENoExecEvent + properties: + foo: + description: Foo is an example field of ENoExecEvent. Edit enoexecevent_types.go + to remove/update + type: string + type: object + status: + description: ENoExecEventStatus defines the observed state of ENoExecEvent + type: object + type: object + served: true + storage: true + subresources: + status: {} diff --git a/config/crd/kustomization.yaml b/config/crd/kustomization.yaml index b403ab829..b95ecdfb3 100644 --- a/config/crd/kustomization.yaml +++ b/config/crd/kustomization.yaml @@ -3,6 +3,7 @@ # It should be run by config/default resources: - bases/multiarch.openshift.io_clusterpodplacementconfigs.yaml +- bases/multiarch.openshift.io_enoexecevents.yaml #+kubebuilder:scaffold:crdkustomizeresource patches: @@ -14,11 +15,13 @@ patchesStrategicMerge: # [WEBHOOK] To enable webhook, uncomment all the sections with [WEBHOOK] prefix. # patches here are for enabling the conversion webhook for each CRD - patches/webhook_in_multiarch_clusterpodplacementconfigs.yaml +#- patches/webhook_in_enoexecevents.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 #- patches/cainjection_in_clusterpodplacementconfigs.yaml +#- patches/cainjection_in_enoexecevents.yaml #+kubebuilder:scaffold:crdkustomizecainjectionpatch # the following config is for teaching kustomize how to do kustomization for CRDs. diff --git a/config/crd/patches/cainjection_in_multiarch_enoexecevents.yaml b/config/crd/patches/cainjection_in_multiarch_enoexecevents.yaml new file mode 100644 index 000000000..3098725d8 --- /dev/null +++ b/config/crd/patches/cainjection_in_multiarch_enoexecevents.yaml @@ -0,0 +1,7 @@ +# The following patch adds a directive for certmanager to inject CA into the CRD +apiVersion: apiextensions.k8s.io/v1 +kind: CustomResourceDefinition +metadata: + annotations: + cert-manager.io/inject-ca-from: $(CERTIFICATE_NAMESPACE)/$(CERTIFICATE_NAME) + name: enoexecevents.multiarch.openshift.io diff --git a/config/crd/patches/webhook_in_multiarch_enoexecevents.yaml b/config/crd/patches/webhook_in_multiarch_enoexecevents.yaml new file mode 100644 index 000000000..85decf13a --- /dev/null +++ b/config/crd/patches/webhook_in_multiarch_enoexecevents.yaml @@ -0,0 +1,16 @@ +# The following patch enables a conversion webhook for the CRD +apiVersion: apiextensions.k8s.io/v1 +kind: CustomResourceDefinition +metadata: + name: enoexecevents.multiarch.openshift.io +spec: + conversion: + strategy: Webhook + webhook: + clientConfig: + service: + namespace: system + name: webhook-service + path: /convert + conversionReviewVersions: + - v1 diff --git a/config/manifests/bases/multiarch-tuning-operator.clusterserviceversion.yaml b/config/manifests/bases/multiarch-tuning-operator.clusterserviceversion.yaml index 3cb445c2d..e88f22bc7 100644 --- a/config/manifests/bases/multiarch-tuning-operator.clusterserviceversion.yaml +++ b/config/manifests/bases/multiarch-tuning-operator.clusterserviceversion.yaml @@ -50,6 +50,11 @@ spec: kind: ClusterPodPlacementConfig name: clusterpodplacementconfigs.multiarch.openshift.io version: v1alpha1 + - description: ENoExecEvent is the Schema for the enoexecevents API + displayName: ENo Exec Event + kind: ENoExecEvent + name: enoexecevents.multiarch.openshift.io + version: v1beta1 description: | The Multiarch Tuning Operator optimizes workload management within multi-architecture clusters and in single-architecture clusters transitioning to multi-architecture environments. diff --git a/config/rbac/multiarch_enoexecevent_editor_role.yaml b/config/rbac/multiarch_enoexecevent_editor_role.yaml new file mode 100644 index 000000000..866a5a0d5 --- /dev/null +++ b/config/rbac/multiarch_enoexecevent_editor_role.yaml @@ -0,0 +1,31 @@ +# permissions for end users to edit enoexecevents. +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRole +metadata: + labels: + app.kubernetes.io/name: clusterrole + app.kubernetes.io/instance: enoexecevent-editor-role + app.kubernetes.io/component: rbac + app.kubernetes.io/created-by: multiarch-tuning-operator + app.kubernetes.io/part-of: multiarch-tuning-operator + app.kubernetes.io/managed-by: kustomize + name: enoexecevent-editor-role +rules: +- apiGroups: + - multiarch.openshift.io + resources: + - enoexecevents + verbs: + - create + - delete + - get + - list + - patch + - update + - watch +- apiGroups: + - multiarch.openshift.io + resources: + - enoexecevents/status + verbs: + - get diff --git a/config/rbac/multiarch_enoexecevent_viewer_role.yaml b/config/rbac/multiarch_enoexecevent_viewer_role.yaml new file mode 100644 index 000000000..cdf306199 --- /dev/null +++ b/config/rbac/multiarch_enoexecevent_viewer_role.yaml @@ -0,0 +1,27 @@ +# permissions for end users to view enoexecevents. +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRole +metadata: + labels: + app.kubernetes.io/name: clusterrole + app.kubernetes.io/instance: enoexecevent-viewer-role + app.kubernetes.io/component: rbac + app.kubernetes.io/created-by: multiarch-tuning-operator + app.kubernetes.io/part-of: multiarch-tuning-operator + app.kubernetes.io/managed-by: kustomize + name: enoexecevent-viewer-role +rules: +- apiGroups: + - multiarch.openshift.io + resources: + - enoexecevents + verbs: + - get + - list + - watch +- apiGroups: + - multiarch.openshift.io + resources: + - enoexecevents/status + verbs: + - get diff --git a/config/rbac/role.yaml b/config/rbac/role.yaml index 6bb572762..679b67652 100644 --- a/config/rbac/role.yaml +++ b/config/rbac/role.yaml @@ -130,6 +130,7 @@ rules: - multiarch.openshift.io resources: - clusterpodplacementconfigs + - enoexecevents verbs: - create - delete @@ -142,12 +143,14 @@ rules: - multiarch.openshift.io resources: - clusterpodplacementconfigs/finalizers + - enoexecevents/finalizers verbs: - update - apiGroups: - multiarch.openshift.io resources: - clusterpodplacementconfigs/status + - enoexecevents/status verbs: - get - patch diff --git a/config/samples/kustomization.yaml b/config/samples/kustomization.yaml index ade72ea17..b28c8526a 100644 --- a/config/samples/kustomization.yaml +++ b/config/samples/kustomization.yaml @@ -1,4 +1,5 @@ ## Append samples you want in your CSV to this file as resources ## resources: - multiarch_v1beta1_clusterpodplacementconfig.yaml +- multiarch_v1beta1_enoexecevent.yaml #+kubebuilder:scaffold:manifestskustomizesamples diff --git a/config/samples/multiarch_v1beta1_enoexecevent.yaml b/config/samples/multiarch_v1beta1_enoexecevent.yaml new file mode 100644 index 000000000..25eab4db3 --- /dev/null +++ b/config/samples/multiarch_v1beta1_enoexecevent.yaml @@ -0,0 +1,12 @@ +apiVersion: multiarch.openshift.io/v1beta1 +kind: ENoExecEvent +metadata: + labels: + app.kubernetes.io/name: enoexecevent + app.kubernetes.io/instance: enoexecevent-sample + app.kubernetes.io/part-of: multiarch-tuning-operator + app.kubernetes.io/managed-by: kustomize + app.kubernetes.io/created-by: multiarch-tuning-operator + name: enoexecevent-sample +spec: + # TODO(user): Add fields here diff --git a/controllers/multiarch/enoexecevent_controller.go b/controllers/multiarch/enoexecevent_controller.go new file mode 100644 index 000000000..7e17f186e --- /dev/null +++ b/controllers/multiarch/enoexecevent_controller.go @@ -0,0 +1,62 @@ +/* +Copyright 2023 Red Hat, Inc. + +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 multiarch + +import ( + "context" + + "k8s.io/apimachinery/pkg/runtime" + ctrl "sigs.k8s.io/controller-runtime" + "sigs.k8s.io/controller-runtime/pkg/client" + "sigs.k8s.io/controller-runtime/pkg/log" + + multiarchv1beta1 "github.com/openshift/multiarch-tuning-operator/apis/multiarch/v1beta1" +) + +// ENoExecEventReconciler reconciles a ENoExecEvent object +type ENoExecEventReconciler struct { + client.Client + Scheme *runtime.Scheme +} + +//+kubebuilder:rbac:groups=multiarch.openshift.io,resources=enoexecevents,verbs=get;list;watch;create;update;patch;delete +//+kubebuilder:rbac:groups=multiarch.openshift.io,resources=enoexecevents/status,verbs=get;update;patch +//+kubebuilder:rbac:groups=multiarch.openshift.io,resources=enoexecevents/finalizers,verbs=update + +// Reconcile is part of the main kubernetes reconciliation loop which aims to +// move the current state of the cluster closer to the desired state. +// TODO(user): Modify the Reconcile function to compare the state specified by +// the ENoExecEvent object against the actual cluster state, and then +// perform operations to make the cluster state reflect the state specified by +// the user. +// +// For more details, check Reconcile and its Result here: +// - https://pkg.go.dev/sigs.k8s.io/controller-runtime@v0.14.1/pkg/reconcile +func (r *ENoExecEventReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) { + _ = log.FromContext(ctx) + + // TODO(user): your logic here + + return ctrl.Result{}, nil +} + +// SetupWithManager sets up the controller with the Manager. +func (r *ENoExecEventReconciler) SetupWithManager(mgr ctrl.Manager) error { + return ctrl.NewControllerManagedBy(mgr). + For(&multiarchv1beta1.ENoExecEvent{}). + Complete(r) +} diff --git a/controllers/multiarch/suite_test.go b/controllers/multiarch/suite_test.go new file mode 100644 index 000000000..0c72d56e3 --- /dev/null +++ b/controllers/multiarch/suite_test.go @@ -0,0 +1,80 @@ +/* +Copyright 2023 Red Hat, Inc. + +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 multiarch + +import ( + "path/filepath" + "testing" + + . "github.com/onsi/ginkgo/v2" + . "github.com/onsi/gomega" + + "k8s.io/client-go/kubernetes/scheme" + "k8s.io/client-go/rest" + "sigs.k8s.io/controller-runtime/pkg/client" + "sigs.k8s.io/controller-runtime/pkg/envtest" + logf "sigs.k8s.io/controller-runtime/pkg/log" + "sigs.k8s.io/controller-runtime/pkg/log/zap" + + multiarchv1beta1 "github.com/openshift/multiarch-tuning-operator/apis/multiarch/v1beta1" + //+kubebuilder:scaffold:imports +) + +// These tests use Ginkgo (BDD-style Go testing framework). Refer to +// http://onsi.github.io/ginkgo/ to learn more about Ginkgo. + +var cfg *rest.Config +var k8sClient client.Client +var testEnv *envtest.Environment + +func TestAPIs(t *testing.T) { + RegisterFailHandler(Fail) + + RunSpecs(t, "Controller Suite") +} + +var _ = BeforeSuite(func() { + logf.SetLogger(zap.New(zap.WriteTo(GinkgoWriter), zap.UseDevMode(true))) + + By("bootstrapping test environment") + testEnv = &envtest.Environment{ + CRDDirectoryPaths: []string{filepath.Join("..", "..", "config", "crd", "bases")}, + ErrorIfCRDPathMissing: true, + } + + var err error + // cfg is defined in this file globally. + cfg, err = testEnv.Start() + Expect(err).NotTo(HaveOccurred()) + Expect(cfg).NotTo(BeNil()) + + err = multiarchv1beta1.AddToScheme(scheme.Scheme) + Expect(err).NotTo(HaveOccurred()) + + //+kubebuilder:scaffold:scheme + + k8sClient, err = client.New(cfg, client.Options{Scheme: scheme.Scheme}) + Expect(err).NotTo(HaveOccurred()) + Expect(k8sClient).NotTo(BeNil()) + +}) + +var _ = AfterSuite(func() { + By("tearing down the test environment") + err := testEnv.Stop() + Expect(err).NotTo(HaveOccurred()) +}) diff --git a/main.go b/main.go index 270520128..82e069afa 100644 --- a/main.go +++ b/main.go @@ -50,6 +50,7 @@ import ( metricsserver "sigs.k8s.io/controller-runtime/pkg/metrics/server" "sigs.k8s.io/controller-runtime/pkg/webhook" + multiarchcontrollers "github.com/openshift/multiarch-tuning-operator/controllers/multiarch" //+kubebuilder:scaffold:imports "github.com/openshift/library-go/pkg/operator/events" @@ -169,6 +170,13 @@ func main() { }) must(err, "unable to create manager") + if err = (&multiarchcontrollers.ENoExecEventReconciler{ + Client: mgr.GetClient(), + Scheme: mgr.GetScheme(), + }).SetupWithManager(mgr); err != nil { + setupLog.Error(err, "unable to create controller", "controller", "ENoExecEvent") + os.Exit(1) + } //+kubebuilder:scaffold:builder must(mgr.AddHealthzCheck("healthz", healthz.Ping), "unable to set up health check") must(mgr.AddReadyzCheck("readyz", healthz.Ping), "unable to set up ready check")