From 4a46dce0e7ad33116220cbf306466c48b1aea946 Mon Sep 17 00:00:00 2001 From: Gerardo Gomez Date: Thu, 14 Jul 2022 16:14:46 +0200 Subject: [PATCH 1/2] refactor(fl-operator): rearrange fl-opertor to adhere to the operator-sdk project layout This will allow operator-sdk cli to create new resources and controllers --- components/fl-operator/Makefile | 6 +++--- components/fl-operator/PROJECT | 4 ++-- .../crd/bases/fl.katulu.io_floperators.yaml | 0 .../{kustomize => config}/crd/kustomization.yaml | 0 .../{kustomize => config}/crd/kustomizeconfig.yaml | 0 .../crd/patches/cainjection_in_floperators.yaml | 0 .../crd/patches/webhook_in_floperators.yaml | 0 .../{kustomize => config}/default/kustomization.yaml | 0 .../default/manager_auth_proxy_patch.yaml | 0 .../{kustomize => config}/default/manager_config_patch.yaml | 0 .../manager/controller_manager_config.yaml | 0 .../{kustomize => config}/manager/kustomization.yaml | 0 .../fl-operator/{kustomize => config}/manager/manager.yaml | 0 .../rbac/auth_proxy_client_clusterrole.yaml | 0 .../{kustomize => config}/rbac/auth_proxy_role.yaml | 0 .../{kustomize => config}/rbac/auth_proxy_role_binding.yaml | 0 .../{kustomize => config}/rbac/auth_proxy_service.yaml | 0 .../{kustomize => config}/rbac/floperator_editor_role.yaml | 0 .../{kustomize => config}/rbac/floperator_viewer_role.yaml | 0 .../{kustomize => config}/rbac/kustomization.yaml | 0 .../{kustomize => config}/rbac/leader_election_role.yaml | 0 .../rbac/leader_election_role_binding.yaml | 0 components/fl-operator/{kustomize => config}/rbac/role.yaml | 0 .../{kustomize => config}/rbac/role_binding.yaml | 0 .../{kustomize => config}/rbac/service_account.yaml | 0 .../samples/fl_v1alpha1_floperator.yaml | 0 .../{kustomize => config}/samples/kustomization.yaml | 0 components/fl-operator/controllers/suite_test.go | 2 +- components/fl-operator/kustomization.yaml.tpl | 2 +- components/fl-operator/{cmd/manager => }/main.go | 0 30 files changed, 7 insertions(+), 7 deletions(-) rename components/fl-operator/{kustomize => config}/crd/bases/fl.katulu.io_floperators.yaml (100%) rename components/fl-operator/{kustomize => config}/crd/kustomization.yaml (100%) rename components/fl-operator/{kustomize => config}/crd/kustomizeconfig.yaml (100%) rename components/fl-operator/{kustomize => config}/crd/patches/cainjection_in_floperators.yaml (100%) rename components/fl-operator/{kustomize => config}/crd/patches/webhook_in_floperators.yaml (100%) rename components/fl-operator/{kustomize => config}/default/kustomization.yaml (100%) rename components/fl-operator/{kustomize => config}/default/manager_auth_proxy_patch.yaml (100%) rename components/fl-operator/{kustomize => config}/default/manager_config_patch.yaml (100%) rename components/fl-operator/{kustomize => config}/manager/controller_manager_config.yaml (100%) rename components/fl-operator/{kustomize => config}/manager/kustomization.yaml (100%) rename components/fl-operator/{kustomize => config}/manager/manager.yaml (100%) rename components/fl-operator/{kustomize => config}/rbac/auth_proxy_client_clusterrole.yaml (100%) rename components/fl-operator/{kustomize => config}/rbac/auth_proxy_role.yaml (100%) rename components/fl-operator/{kustomize => config}/rbac/auth_proxy_role_binding.yaml (100%) rename components/fl-operator/{kustomize => config}/rbac/auth_proxy_service.yaml (100%) rename components/fl-operator/{kustomize => config}/rbac/floperator_editor_role.yaml (100%) rename components/fl-operator/{kustomize => config}/rbac/floperator_viewer_role.yaml (100%) rename components/fl-operator/{kustomize => config}/rbac/kustomization.yaml (100%) rename components/fl-operator/{kustomize => config}/rbac/leader_election_role.yaml (100%) rename components/fl-operator/{kustomize => config}/rbac/leader_election_role_binding.yaml (100%) rename components/fl-operator/{kustomize => config}/rbac/role.yaml (100%) rename components/fl-operator/{kustomize => config}/rbac/role_binding.yaml (100%) rename components/fl-operator/{kustomize => config}/rbac/service_account.yaml (100%) rename components/fl-operator/{kustomize => config}/samples/fl_v1alpha1_floperator.yaml (100%) rename components/fl-operator/{kustomize => config}/samples/kustomization.yaml (100%) rename components/fl-operator/{cmd/manager => }/main.go (100%) diff --git a/components/fl-operator/Makefile b/components/fl-operator/Makefile index 6df477f..76936b4 100644 --- a/components/fl-operator/Makefile +++ b/components/fl-operator/Makefile @@ -48,8 +48,8 @@ bin/setup-envtest: .PHONY: manifests manifests: bin/controller-gen ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects. PATH="$(GOBIN):$(PATH)" controller-gen rbac:roleName=manager-role crd webhook paths="./..." \ - output:crd:artifacts:config=kustomize/crd/bases \ - output:rbac:artifacts:config=kustomize/rbac + output:crd:artifacts:config=config/crd/bases \ + output:rbac:artifacts:config=config/rbac .PHONY: generate generate: bin/controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations. @@ -63,7 +63,7 @@ test: bin/setup-envtest ## Run tests. .PHONY: build build: generate ## Build manager binary. - CGO_ENABLED=0 go build -o bin/manager ./cmd/manager + CGO_ENABLED=0 go build -o bin/manager main.go .PHONY: run run: diff --git a/components/fl-operator/PROJECT b/components/fl-operator/PROJECT index e22a268..1aab484 100644 --- a/components/fl-operator/PROJECT +++ b/components/fl-operator/PROJECT @@ -5,7 +5,7 @@ plugins: manifests.sdk.operatorframework.io/v2: {} scorecard.sdk.operatorframework.io/v2: {} projectName: fl-operator -repo: github.com/katulu-io/fl-suite +repo: github.com/katulu-io/fl-suite/fl-operator resources: - api: crdVersion: v1 @@ -14,6 +14,6 @@ resources: domain: katulu.io group: fl kind: FlOperator - path: github.com/katulu-io/fl-suite/api/v1alpha1 + path: github.com/katulu-io/fl-suite/fl-operator/api/v1alpha1 version: v1alpha1 version: "3" diff --git a/components/fl-operator/kustomize/crd/bases/fl.katulu.io_floperators.yaml b/components/fl-operator/config/crd/bases/fl.katulu.io_floperators.yaml similarity index 100% rename from components/fl-operator/kustomize/crd/bases/fl.katulu.io_floperators.yaml rename to components/fl-operator/config/crd/bases/fl.katulu.io_floperators.yaml diff --git a/components/fl-operator/kustomize/crd/kustomization.yaml b/components/fl-operator/config/crd/kustomization.yaml similarity index 100% rename from components/fl-operator/kustomize/crd/kustomization.yaml rename to components/fl-operator/config/crd/kustomization.yaml diff --git a/components/fl-operator/kustomize/crd/kustomizeconfig.yaml b/components/fl-operator/config/crd/kustomizeconfig.yaml similarity index 100% rename from components/fl-operator/kustomize/crd/kustomizeconfig.yaml rename to components/fl-operator/config/crd/kustomizeconfig.yaml diff --git a/components/fl-operator/kustomize/crd/patches/cainjection_in_floperators.yaml b/components/fl-operator/config/crd/patches/cainjection_in_floperators.yaml similarity index 100% rename from components/fl-operator/kustomize/crd/patches/cainjection_in_floperators.yaml rename to components/fl-operator/config/crd/patches/cainjection_in_floperators.yaml diff --git a/components/fl-operator/kustomize/crd/patches/webhook_in_floperators.yaml b/components/fl-operator/config/crd/patches/webhook_in_floperators.yaml similarity index 100% rename from components/fl-operator/kustomize/crd/patches/webhook_in_floperators.yaml rename to components/fl-operator/config/crd/patches/webhook_in_floperators.yaml diff --git a/components/fl-operator/kustomize/default/kustomization.yaml b/components/fl-operator/config/default/kustomization.yaml similarity index 100% rename from components/fl-operator/kustomize/default/kustomization.yaml rename to components/fl-operator/config/default/kustomization.yaml diff --git a/components/fl-operator/kustomize/default/manager_auth_proxy_patch.yaml b/components/fl-operator/config/default/manager_auth_proxy_patch.yaml similarity index 100% rename from components/fl-operator/kustomize/default/manager_auth_proxy_patch.yaml rename to components/fl-operator/config/default/manager_auth_proxy_patch.yaml diff --git a/components/fl-operator/kustomize/default/manager_config_patch.yaml b/components/fl-operator/config/default/manager_config_patch.yaml similarity index 100% rename from components/fl-operator/kustomize/default/manager_config_patch.yaml rename to components/fl-operator/config/default/manager_config_patch.yaml diff --git a/components/fl-operator/kustomize/manager/controller_manager_config.yaml b/components/fl-operator/config/manager/controller_manager_config.yaml similarity index 100% rename from components/fl-operator/kustomize/manager/controller_manager_config.yaml rename to components/fl-operator/config/manager/controller_manager_config.yaml diff --git a/components/fl-operator/kustomize/manager/kustomization.yaml b/components/fl-operator/config/manager/kustomization.yaml similarity index 100% rename from components/fl-operator/kustomize/manager/kustomization.yaml rename to components/fl-operator/config/manager/kustomization.yaml diff --git a/components/fl-operator/kustomize/manager/manager.yaml b/components/fl-operator/config/manager/manager.yaml similarity index 100% rename from components/fl-operator/kustomize/manager/manager.yaml rename to components/fl-operator/config/manager/manager.yaml diff --git a/components/fl-operator/kustomize/rbac/auth_proxy_client_clusterrole.yaml b/components/fl-operator/config/rbac/auth_proxy_client_clusterrole.yaml similarity index 100% rename from components/fl-operator/kustomize/rbac/auth_proxy_client_clusterrole.yaml rename to components/fl-operator/config/rbac/auth_proxy_client_clusterrole.yaml diff --git a/components/fl-operator/kustomize/rbac/auth_proxy_role.yaml b/components/fl-operator/config/rbac/auth_proxy_role.yaml similarity index 100% rename from components/fl-operator/kustomize/rbac/auth_proxy_role.yaml rename to components/fl-operator/config/rbac/auth_proxy_role.yaml diff --git a/components/fl-operator/kustomize/rbac/auth_proxy_role_binding.yaml b/components/fl-operator/config/rbac/auth_proxy_role_binding.yaml similarity index 100% rename from components/fl-operator/kustomize/rbac/auth_proxy_role_binding.yaml rename to components/fl-operator/config/rbac/auth_proxy_role_binding.yaml diff --git a/components/fl-operator/kustomize/rbac/auth_proxy_service.yaml b/components/fl-operator/config/rbac/auth_proxy_service.yaml similarity index 100% rename from components/fl-operator/kustomize/rbac/auth_proxy_service.yaml rename to components/fl-operator/config/rbac/auth_proxy_service.yaml diff --git a/components/fl-operator/kustomize/rbac/floperator_editor_role.yaml b/components/fl-operator/config/rbac/floperator_editor_role.yaml similarity index 100% rename from components/fl-operator/kustomize/rbac/floperator_editor_role.yaml rename to components/fl-operator/config/rbac/floperator_editor_role.yaml diff --git a/components/fl-operator/kustomize/rbac/floperator_viewer_role.yaml b/components/fl-operator/config/rbac/floperator_viewer_role.yaml similarity index 100% rename from components/fl-operator/kustomize/rbac/floperator_viewer_role.yaml rename to components/fl-operator/config/rbac/floperator_viewer_role.yaml diff --git a/components/fl-operator/kustomize/rbac/kustomization.yaml b/components/fl-operator/config/rbac/kustomization.yaml similarity index 100% rename from components/fl-operator/kustomize/rbac/kustomization.yaml rename to components/fl-operator/config/rbac/kustomization.yaml diff --git a/components/fl-operator/kustomize/rbac/leader_election_role.yaml b/components/fl-operator/config/rbac/leader_election_role.yaml similarity index 100% rename from components/fl-operator/kustomize/rbac/leader_election_role.yaml rename to components/fl-operator/config/rbac/leader_election_role.yaml diff --git a/components/fl-operator/kustomize/rbac/leader_election_role_binding.yaml b/components/fl-operator/config/rbac/leader_election_role_binding.yaml similarity index 100% rename from components/fl-operator/kustomize/rbac/leader_election_role_binding.yaml rename to components/fl-operator/config/rbac/leader_election_role_binding.yaml diff --git a/components/fl-operator/kustomize/rbac/role.yaml b/components/fl-operator/config/rbac/role.yaml similarity index 100% rename from components/fl-operator/kustomize/rbac/role.yaml rename to components/fl-operator/config/rbac/role.yaml diff --git a/components/fl-operator/kustomize/rbac/role_binding.yaml b/components/fl-operator/config/rbac/role_binding.yaml similarity index 100% rename from components/fl-operator/kustomize/rbac/role_binding.yaml rename to components/fl-operator/config/rbac/role_binding.yaml diff --git a/components/fl-operator/kustomize/rbac/service_account.yaml b/components/fl-operator/config/rbac/service_account.yaml similarity index 100% rename from components/fl-operator/kustomize/rbac/service_account.yaml rename to components/fl-operator/config/rbac/service_account.yaml diff --git a/components/fl-operator/kustomize/samples/fl_v1alpha1_floperator.yaml b/components/fl-operator/config/samples/fl_v1alpha1_floperator.yaml similarity index 100% rename from components/fl-operator/kustomize/samples/fl_v1alpha1_floperator.yaml rename to components/fl-operator/config/samples/fl_v1alpha1_floperator.yaml diff --git a/components/fl-operator/kustomize/samples/kustomization.yaml b/components/fl-operator/config/samples/kustomization.yaml similarity index 100% rename from components/fl-operator/kustomize/samples/kustomization.yaml rename to components/fl-operator/config/samples/kustomization.yaml diff --git a/components/fl-operator/controllers/suite_test.go b/components/fl-operator/controllers/suite_test.go index bccb2ad..0f58c6b 100644 --- a/components/fl-operator/controllers/suite_test.go +++ b/components/fl-operator/controllers/suite_test.go @@ -60,7 +60,7 @@ var _ = BeforeSuite(func() { By("bootstrapping test environment") testEnv = &envtest.Environment{ - CRDDirectoryPaths: []string{filepath.Join("..", "kustomize", "crd", "bases")}, + CRDDirectoryPaths: []string{filepath.Join("..", "config", "crd", "bases")}, ErrorIfCRDPathMissing: true, } diff --git a/components/fl-operator/kustomization.yaml.tpl b/components/fl-operator/kustomization.yaml.tpl index 4693f3c..0ca7945 100644 --- a/components/fl-operator/kustomization.yaml.tpl +++ b/components/fl-operator/kustomization.yaml.tpl @@ -1,7 +1,7 @@ apiVersion: kustomize.config.k8s.io/v1beta1 kind: Kustomization resources: -- kustomize/default +- config/default commonLabels: app: fl-operator app.kubernetes.io/component: fl-operator diff --git a/components/fl-operator/cmd/manager/main.go b/components/fl-operator/main.go similarity index 100% rename from components/fl-operator/cmd/manager/main.go rename to components/fl-operator/main.go From 805e00ac546787a25a486653d54431fb5cdb764d Mon Sep 17 00:00:00 2001 From: Gerardo Gomez Date: Thu, 14 Jul 2022 17:03:31 +0200 Subject: [PATCH 2/2] docs(fl-operator): document how to add new apis inside the fl-operator --- components/fl-operator/README.md | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 components/fl-operator/README.md diff --git a/components/fl-operator/README.md b/components/fl-operator/README.md new file mode 100644 index 0000000..e60a420 --- /dev/null +++ b/components/fl-operator/README.md @@ -0,0 +1,19 @@ +# FL Operator + +Kubernetes operator in charge of scheduling federated learning clients (e.g flower-clients) on-demand based on running +fl-suite workflows. + +## Development + +This project follows the [operator-sdk project layout](https://sdk.operatorframework.io/docs/overview/project-layout/#operator-sdk-project-layout). + +### Create a new API + +The `operator-sdk` is used to generate new APIs. For installation instructions check the [documentation](https://sdk.operatorframework.io/docs/installation/). + +To create a new API with resources and controllers use the following command: + +```shell +# Replace $KIND_NAME with the new API name +operator-sdk create api --verbose --group fl --version v1alpha1 --kind $KIND_NAME --resource --controller +```