From a32141f3b31908f34b8daada1525a1db1870b12d Mon Sep 17 00:00:00 2001 From: Andrej Petras Date: Fri, 1 Dec 2023 16:03:53 +0100 Subject: [PATCH] feat: update helm chart for deployment --- ...ducts.io.github.onecx.product.store-v1.yml | 51 +++++++++++++++++++ .../helm/templates/cluster-role-binding.yaml | 11 ---- .../operator-cluster-role-binding.yaml | 12 +++++ .../helm/templates/operator-cluster-role.yaml | 12 +++++ .../product-cluster-role-binding.yaml | 43 ++++++++++++++++ ...er-role.yaml => product-cluster-role.yaml} | 0 src/main/helm/values.yaml | 8 ++- ...Reconciler.java => ProductController.java} | 6 +-- ...ava => ProductControllerResponseTest.java} | 4 +- ...erTest.java => ProductControllerTest.java} | 4 +- 10 files changed, 132 insertions(+), 19 deletions(-) create mode 100644 src/main/helm/crds/products.io.github.onecx.product.store-v1.yml delete mode 100644 src/main/helm/templates/cluster-role-binding.yaml create mode 100644 src/main/helm/templates/operator-cluster-role-binding.yaml create mode 100644 src/main/helm/templates/operator-cluster-role.yaml create mode 100644 src/main/helm/templates/product-cluster-role-binding.yaml rename src/main/helm/templates/{cluster-role.yaml => product-cluster-role.yaml} (100%) rename src/main/java/io/github/onecx/product/store/operator/{ProductReconciler.java => ProductController.java} (92%) rename src/test/java/io/github/onecx/product/store/operator/{ProductReconcilerResponseTest.java => ProductControllerResponseTest.java} (93%) rename src/test/java/io/github/onecx/product/store/operator/{ProductReconcilerTest.java => ProductControllerTest.java} (97%) diff --git a/src/main/helm/crds/products.io.github.onecx.product.store-v1.yml b/src/main/helm/crds/products.io.github.onecx.product.store-v1.yml new file mode 100644 index 0000000..4082970 --- /dev/null +++ b/src/main/helm/crds/products.io.github.onecx.product.store-v1.yml @@ -0,0 +1,51 @@ +# Generated by Fabric8 CRDGenerator, manual edits might get overwritten! +apiVersion: apiextensions.k8s.io/v1 +kind: CustomResourceDefinition +metadata: + name: products.io.github.onecx.product.store +spec: + group: io.github.onecx.product.store + names: + kind: Product + plural: products + singular: product + scope: Namespaced + versions: + - name: v1 + schema: + openAPIV3Schema: + properties: + spec: + properties: + image-url: + type: string + name: + type: string + base-path: + type: string + description: + type: string + type: object + status: + properties: + response-code: + type: integer + product-name: + type: string + status: + enum: + - UPDATED + - CREATED + - ERROR + - UNDEFINED + type: string + message: + type: string + observedGeneration: + type: integer + type: object + type: object + served: true + storage: true + subresources: + status: {} diff --git a/src/main/helm/templates/cluster-role-binding.yaml b/src/main/helm/templates/cluster-role-binding.yaml deleted file mode 100644 index 48588e3..0000000 --- a/src/main/helm/templates/cluster-role-binding.yaml +++ /dev/null @@ -1,11 +0,0 @@ -apiVersion: rbac.authorization.k8s.io/v1 -kind: ClusterRoleBinding -metadata: - name: {{ .Release.Name }}-{{ .Values.app.name }}-role-binding -roleRef: - kind: ClusterRole - apiGroup: rbac.authorization.k8s.io - name: {{ .Release.Name }}-{{ .Values.app.name }}-cluster-role -subjects: - - kind: ServiceAccount - name: {{ .Release.Name }}-{{ .Values.app.name }} \ No newline at end of file diff --git a/src/main/helm/templates/operator-cluster-role-binding.yaml b/src/main/helm/templates/operator-cluster-role-binding.yaml new file mode 100644 index 0000000..5e739ff --- /dev/null +++ b/src/main/helm/templates/operator-cluster-role-binding.yaml @@ -0,0 +1,12 @@ +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRoleBinding +metadata: + name: {{ .Release.Name }}-{{ .Values.app.name }}-validating-role-binding +roleRef: + kind: ClusterRole + apiGroup: rbac.authorization.k8s.io + name: {{ .Release.Name }}-{{ .Values.app.name }}-validating-cluster-role +subjects: + - kind: ServiceAccount + name: {{ .Release.Name }}-{{ .Values.app.name }} + namespace: {{ .Release.Namespace }} diff --git a/src/main/helm/templates/operator-cluster-role.yaml b/src/main/helm/templates/operator-cluster-role.yaml new file mode 100644 index 0000000..4d51a68 --- /dev/null +++ b/src/main/helm/templates/operator-cluster-role.yaml @@ -0,0 +1,12 @@ +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRole +metadata: + name: {{ .Release.Name }}-{{ .Values.app.name }}-validating-cluster-role +rules: + - apiGroups: + - apiextensions.k8s.io + resources: + - customresourcedefinitions + verbs: + - get + - list diff --git a/src/main/helm/templates/product-cluster-role-binding.yaml b/src/main/helm/templates/product-cluster-role-binding.yaml new file mode 100644 index 0000000..1c2995f --- /dev/null +++ b/src/main/helm/templates/product-cluster-role-binding.yaml @@ -0,0 +1,43 @@ +{{ if eq $.Values.watchNamespaces "JOSDK_WATCH_CURRENT" }} +apiVersion: rbac.authorization.k8s.io/v1 +kind: RoleBinding +metadata: + name: {{ .Release.Name }}-{{ .Values.app.name }}-role-binding +roleRef: + kind: ClusterRole + apiGroup: rbac.authorization.k8s.io + name: {{ .Release.Name }}-{{ .Values.app.name }}-cluster-role +subjects: + - kind: ServiceAccount + name: {{ .Release.Name }}-{{ .Values.app.name }} +{{ else if eq $.Values.watchNamespaces "JOSDK_ALL_NAMESPACES" }} +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRoleBinding +metadata: + name: {{ .Release.Name }}-{{ .Values.app.name }}-role-binding +roleRef: + kind: ClusterRole + apiGroup: rbac.authorization.k8s.io + name: {{ .Release.Name }}-{{ .Values.app.name }}-cluster-role +subjects: + - kind: ServiceAccount + name: {{ .Release.Name }}-{{ .Values.app.name }} + namespace: {{ $.Release.Namespace }} +{{ else }} +{{ range $anamespace := ( split "," $.Values.watchNamespaces ) }} +apiVersion: rbac.authorization.k8s.io/v1 +kind: RoleBinding +metadata: + name: {{ .Release.Name }}-{{ .Values.app.name }}-role-binding + namespace: {{ $anamespace }} +roleRef: + kind: ClusterRole + apiGroup: rbac.authorization.k8s.io + name: {{ .Release.Name }}-{{ .Values.app.name }}-cluster-role +subjects: + - kind: ServiceAccount + name: {{ .Release.Name }}-{{ .Values.app.name }} + namespace: {{ $.Release.Namespace }} +--- +{{- end }} +{{- end }} \ No newline at end of file diff --git a/src/main/helm/templates/cluster-role.yaml b/src/main/helm/templates/product-cluster-role.yaml similarity index 100% rename from src/main/helm/templates/cluster-role.yaml rename to src/main/helm/templates/product-cluster-role.yaml diff --git a/src/main/helm/values.yaml b/src/main/helm/values.yaml index 61b6cef..a6fbbf0 100644 --- a/src/main/helm/values.yaml +++ b/src/main/helm/values.yaml @@ -2,7 +2,10 @@ app: name: product-operator image: repository: "onecx/onecx-product-store-operator" - tag: 999-SNAPSHOT + env: + "TKIT_LOG_JSON_ENABLED": "false" + # See watchNamespaces + "QUARKUS_OPERATOR_SDK_CONTROLLERS_PRODUCT_NAMESPACES": "JOSDK_WATCH_CURRENT" envCustom: - name: KUBERNETES_NAMESPACE valueFrom: @@ -10,3 +13,6 @@ app: fieldPath: metadata.namespace serviceAccount: enabled: true + +# Values: JOSDK_WATCH_CURRENT, JOSDK_ALL_NAMESPACES or comma separated list of namespaces +watchNamespaces: "JOSDK_WATCH_CURRENT" diff --git a/src/main/java/io/github/onecx/product/store/operator/ProductReconciler.java b/src/main/java/io/github/onecx/product/store/operator/ProductController.java similarity index 92% rename from src/main/java/io/github/onecx/product/store/operator/ProductReconciler.java rename to src/main/java/io/github/onecx/product/store/operator/ProductController.java index 0828cef..c41eab1 100644 --- a/src/main/java/io/github/onecx/product/store/operator/ProductReconciler.java +++ b/src/main/java/io/github/onecx/product/store/operator/ProductController.java @@ -11,9 +11,9 @@ import io.javaoperatorsdk.operator.processing.event.source.filter.OnAddFilter; import io.javaoperatorsdk.operator.processing.event.source.filter.OnUpdateFilter; -@ControllerConfiguration(onAddFilter = ProductReconciler.AddFilter.class, onUpdateFilter = ProductReconciler.UpdateFilter.class) -public class ProductReconciler implements Reconciler, ErrorStatusHandler { - private static final Logger log = LoggerFactory.getLogger(ProductReconciler.class); +@ControllerConfiguration(name = "product", onAddFilter = ProductController.AddFilter.class, onUpdateFilter = ProductController.UpdateFilter.class) +public class ProductController implements Reconciler, ErrorStatusHandler { + private static final Logger log = LoggerFactory.getLogger(ProductController.class); @Inject ProductStoreService service; diff --git a/src/test/java/io/github/onecx/product/store/operator/ProductReconcilerResponseTest.java b/src/test/java/io/github/onecx/product/store/operator/ProductControllerResponseTest.java similarity index 93% rename from src/test/java/io/github/onecx/product/store/operator/ProductReconcilerResponseTest.java rename to src/test/java/io/github/onecx/product/store/operator/ProductControllerResponseTest.java index 26a9293..3136fef 100644 --- a/src/test/java/io/github/onecx/product/store/operator/ProductReconcilerResponseTest.java +++ b/src/test/java/io/github/onecx/product/store/operator/ProductControllerResponseTest.java @@ -16,13 +16,13 @@ import io.quarkus.test.junit.QuarkusTest; @QuarkusTest -class ProductReconcilerResponseTest extends AbstractTest { +class ProductControllerResponseTest extends AbstractTest { @InjectMock ProductStoreService productStoreService; @Inject - ProductReconciler reconciler; + ProductController reconciler; @BeforeEach void beforeAll() { diff --git a/src/test/java/io/github/onecx/product/store/operator/ProductReconcilerTest.java b/src/test/java/io/github/onecx/product/store/operator/ProductControllerTest.java similarity index 97% rename from src/test/java/io/github/onecx/product/store/operator/ProductReconcilerTest.java rename to src/test/java/io/github/onecx/product/store/operator/ProductControllerTest.java index dc9bdd5..1717ca2 100644 --- a/src/test/java/io/github/onecx/product/store/operator/ProductReconcilerTest.java +++ b/src/test/java/io/github/onecx/product/store/operator/ProductControllerTest.java @@ -24,9 +24,9 @@ import io.quarkus.test.junit.QuarkusTest; @QuarkusTest -class ProductReconcilerTest extends AbstractTest { +class ProductControllerTest extends AbstractTest { - final static Logger log = LoggerFactory.getLogger(ProductReconcilerTest.class); + final static Logger log = LoggerFactory.getLogger(ProductControllerTest.class); @Inject Operator operator;