diff --git a/src/main/helm/crds/microfrontends.io.github.onecx.product.store-v1.yml b/src/main/helm/crds/microfrontends.io.github.onecx.product.store-v1.yml new file mode 100644 index 0000000..f0d2c95 --- /dev/null +++ b/src/main/helm/crds/microfrontends.io.github.onecx.product.store-v1.yml @@ -0,0 +1,76 @@ +# Generated by Fabric8 CRDGenerator, manual edits might get overwritten! +apiVersion: apiextensions.k8s.io/v1 +kind: CustomResourceDefinition +metadata: + name: microfrontends.io.github.onecx.product.store +spec: + group: io.github.onecx.product.store + names: + kind: Microfrontend + plural: microfrontends + singular: microfrontend + scope: Namespaced + versions: + - name: v1 + schema: + openAPIV3Schema: + properties: + spec: + properties: + display-name: + type: string + app-id: + type: string + product-name: + type: string + remote-entry: + type: string + wc-tag-name: + type: string + remote-name: + type: string + exposed-module: + type: string + mfe-id: + type: string + note: + type: string + base-path: + type: string + app-version: + type: string + remote-base-url: + type: string + module-type: + enum: + - WEBCOMPONENT + - ANGULAR + type: string + contact: + type: string + type: object + status: + properties: + response-code: + type: integer + status: + enum: + - UPDATED + - ERROR + - CREATED + - UNDEFINED + type: string + product-name: + type: string + mfe-id: + 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/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/product-cluster-role.yaml b/src/main/helm/templates/product-cluster-role.yaml new file mode 100644 index 0000000..4d29cc7 --- /dev/null +++ b/src/main/helm/templates/product-cluster-role.yaml @@ -0,0 +1,19 @@ +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRole +metadata: + name: {{ .Release.Name }}-{{ .Values.app.name }}-cluster-role +rules: + - apiGroups: + - io.github.onecx.product.store + resources: + - "microfrontends" + - "microfrontends/status" + - "microfrontends/finalizers" + verbs: + - get + - list + - watch + - patch + - update + - create + - delete \ No newline at end of file diff --git a/src/main/helm/templates/service-account.yaml b/src/main/helm/templates/service-account.yaml new file mode 100644 index 0000000..56ccce8 --- /dev/null +++ b/src/main/helm/templates/service-account.yaml @@ -0,0 +1,4 @@ +apiVersion: v1 +kind: ServiceAccount +metadata: + name: {{ .Release.Name }}-{{ .Values.app.name }} \ No newline at end of file diff --git a/src/main/helm/values.yaml b/src/main/helm/values.yaml index 9bdd554..dd990d6 100644 --- a/src/main/helm/values.yaml +++ b/src/main/helm/values.yaml @@ -1,4 +1,17 @@ app: + name: mfe-operator image: repository: "onecx/onecx-product-store-mfe-operator" - tag: 999-SNAPSHOT + env: + # See watchNamespaces + "QUARKUS_OPERATOR_SDK_CONTROLLERS_PRODUCT_NAMESPACES": "JOSDK_WATCH_CURRENT" + envCustom: + - name: KUBERNETES_NAMESPACE + valueFrom: + fieldRef: + fieldPath: metadata.namespace + serviceAccount: + enabled: true + +# Values: JOSDK_WATCH_CURRENT, JOSDK_ALL_NAMESPACES or comma separated list of namespaces +watchNamespaces: "JOSDK_WATCH_CURRENT" \ No newline at end of file diff --git a/src/main/java/io/github/onecx/product/store/mfe/operator/Microfrontend.java b/src/main/java/io/github/onecx/product/store/mfe/operator/Microfrontend.java index 32b2f7b..784d02f 100644 --- a/src/main/java/io/github/onecx/product/store/mfe/operator/Microfrontend.java +++ b/src/main/java/io/github/onecx/product/store/mfe/operator/Microfrontend.java @@ -6,6 +6,6 @@ import io.fabric8.kubernetes.model.annotation.Version; @Version("v1") -@Group("io.github.onecx.product.store.mfe") +@Group("io.github.onecx.product.store") public class Microfrontend extends CustomResource implements Namespaced { } diff --git a/src/main/java/io/github/onecx/product/store/mfe/operator/ProductMicrofrontendReconciler.java b/src/main/java/io/github/onecx/product/store/mfe/operator/MicrofrontendController.java similarity index 85% rename from src/main/java/io/github/onecx/product/store/mfe/operator/ProductMicrofrontendReconciler.java rename to src/main/java/io/github/onecx/product/store/mfe/operator/MicrofrontendController.java index 1845a52..37d1b95 100644 --- a/src/main/java/io/github/onecx/product/store/mfe/operator/ProductMicrofrontendReconciler.java +++ b/src/main/java/io/github/onecx/product/store/mfe/operator/MicrofrontendController.java @@ -1,5 +1,7 @@ package io.github.onecx.product.store.mfe.operator; +import static io.javaoperatorsdk.operator.api.reconciler.Constants.WATCH_CURRENT_NAMESPACE; + import jakarta.inject.Inject; import jakarta.ws.rs.WebApplicationException; @@ -11,10 +13,10 @@ import io.javaoperatorsdk.operator.processing.event.source.filter.OnAddFilter; import io.javaoperatorsdk.operator.processing.event.source.filter.OnUpdateFilter; -@ControllerConfiguration(onAddFilter = ProductMicrofrontendReconciler.MicrofrontendAddFilter.class, onUpdateFilter = ProductMicrofrontendReconciler.MicrofrontendUpdateFilter.class) -public class ProductMicrofrontendReconciler implements Reconciler, ErrorStatusHandler { +@ControllerConfiguration(name = "microfrontend", namespaces = WATCH_CURRENT_NAMESPACE, onAddFilter = MicrofrontendController.MicrofrontendAddFilter.class, onUpdateFilter = MicrofrontendController.MicrofrontendUpdateFilter.class) +public class MicrofrontendController implements Reconciler, ErrorStatusHandler { - private static final Logger log = LoggerFactory.getLogger(ProductMicrofrontendReconciler.class); + private static final Logger log = LoggerFactory.getLogger(MicrofrontendController.class); @Inject ProductStoreService service; diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 43432e2..c662d86 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -1,25 +1,21 @@ - -# BUILD -quarkus.openapi-generator.codegen.input-base-dir=target/tmp/openapi -quarkus.openapi-generator.codegen.spec.onecx_product_store_operator_mfe_v1_yaml.config-key=product_store_client -quarkus.openapi-generator.codegen.spec.onecx_product_store_operator_mfe_v1_yaml.base-package=gen.io.github.onecx.product.store.mfe.v1 -quarkus.openapi-generator.codegen.spec.onecx_product_store_operator_mfe_v1_yaml.return-response=true - - -# CONFIG - -quarkus.kubernetes-client.devservices.override-kubeconfig=true - -# validate product store name, relevant only for multi-store -onecx.product.store.mfe.operator.multi-enabled=false -onecx.product.store.mfe.operator.name=onecx - - -# TEST -%test.quarkus.mockserver.devservices.config-class-path=true -%test.quarkus.mockserver.devservices.config-file=/mockserver.properties -%test.quarkus.mockserver.devservices.config-dir=/mockserver -%test.quarkus.mockserver.devservices.log=false -%test.quarkus.mockserver.devservices.reuse=true -%test.quarkus.rest-client.product_store_client.url=${quarkus.mockserver.endpoint} - + +# PROD +%prod.quarkus.rest-client.product_store_client.url=http://product-store-svc:8080 + +# BUILD +quarkus.openapi-generator.codegen.input-base-dir=target/tmp/openapi +quarkus.openapi-generator.codegen.spec.onecx_product_store_operator_mfe_v1_yaml.config-key=product_store_client +quarkus.openapi-generator.codegen.spec.onecx_product_store_operator_mfe_v1_yaml.base-package=gen.io.github.onecx.product.store.mfe.v1 +quarkus.openapi-generator.codegen.spec.onecx_product_store_operator_mfe_v1_yaml.return-response=true + +# CONFIG +quarkus.kubernetes-client.devservices.override-kubeconfig=true + +# TEST +%test.quarkus.mockserver.devservices.config-class-path=true +%test.quarkus.mockserver.devservices.config-file=/mockserver.properties +%test.quarkus.mockserver.devservices.config-dir=/mockserver +%test.quarkus.mockserver.devservices.log=false +%test.quarkus.mockserver.devservices.reuse=true +%test.quarkus.rest-client.product_store_client.url=${quarkus.mockserver.endpoint} + diff --git a/src/test/java/io/github/onecx/product/store/mfe/operator/ProductMicrofrontendReconcilerResponseTest.java b/src/test/java/io/github/onecx/product/store/mfe/operator/MicrofrontendControllerResponseTest.java similarity index 92% rename from src/test/java/io/github/onecx/product/store/mfe/operator/ProductMicrofrontendReconcilerResponseTest.java rename to src/test/java/io/github/onecx/product/store/mfe/operator/MicrofrontendControllerResponseTest.java index a669bd3..a1c9f71 100644 --- a/src/test/java/io/github/onecx/product/store/mfe/operator/ProductMicrofrontendReconcilerResponseTest.java +++ b/src/test/java/io/github/onecx/product/store/mfe/operator/MicrofrontendControllerResponseTest.java @@ -16,13 +16,13 @@ import io.quarkus.test.junit.QuarkusTest; @QuarkusTest -class ProductMicrofrontendReconcilerResponseTest extends AbstractTest { +class MicrofrontendControllerResponseTest extends AbstractTest { @InjectMock ProductStoreService productStoreService; @Inject - ProductMicrofrontendReconciler reconciler; + MicrofrontendController reconciler; @BeforeEach void beforeAll() { diff --git a/src/test/java/io/github/onecx/product/store/mfe/operator/ProductMicrofrontendReconcilerTest.java b/src/test/java/io/github/onecx/product/store/mfe/operator/MicrofrontendControllerTest.java similarity index 97% rename from src/test/java/io/github/onecx/product/store/mfe/operator/ProductMicrofrontendReconcilerTest.java rename to src/test/java/io/github/onecx/product/store/mfe/operator/MicrofrontendControllerTest.java index 06f9a1d..6143e07 100644 --- a/src/test/java/io/github/onecx/product/store/mfe/operator/ProductMicrofrontendReconcilerTest.java +++ b/src/test/java/io/github/onecx/product/store/mfe/operator/MicrofrontendControllerTest.java @@ -24,9 +24,9 @@ import io.quarkus.test.junit.QuarkusTest; @QuarkusTest -class ProductMicrofrontendReconcilerTest extends AbstractTest { +class MicrofrontendControllerTest extends AbstractTest { - final static Logger log = LoggerFactory.getLogger(ProductMicrofrontendReconcilerTest.class); + final static Logger log = LoggerFactory.getLogger(MicrofrontendControllerTest.class); @Inject Operator operator;