Repository: kumahq/kuma
Pull request #3256 (2021-11-22 21:46:43)

chore(*) remove RBAC generator (backport #3176)
This is an automatic backport of pull request #3176 done by [Mergify](https://mergify.com).
Cherry-pick of 3253c9f4fb3b07159654281e23be3203c27e6453 has failed:
```
On branch mergify/bp/release-1.4/pr-3176
Your branch is up to date with 'origin/release-1.4'.

You are currently cherry-picking commit 3253c9f4.
  (fix conflicts and run "git cherry-pick --continue")
  (use "git cherry-pick --skip" to skip this patch)
  (use "git cherry-pick --abort" to cancel the cherry-pick operation)

Changes to be committed:
	modified:   mk/check.mk
	modified:   mk/generate.mk
	modified:   pkg/plugins/resources/k8s/native/Makefile
	deleted:    pkg/plugins/resources/k8s/native/config/rbac/auth_proxy_role.yaml
	deleted:    pkg/plugins/resources/k8s/native/config/rbac/auth_proxy_role_binding.yaml
	deleted:    pkg/plugins/resources/k8s/native/config/rbac/auth_proxy_service.yaml
	deleted:    pkg/plugins/resources/k8s/native/config/rbac/kustomization.yaml
	deleted:    pkg/plugins/resources/k8s/native/config/rbac/role_binding.yaml
	deleted:    pkg/plugins/resources/k8s/native/controllers/suite_test.go

Unmerged paths:
  (use "git add/rm <file>..." as appropriate to mark resolution)
	deleted by them: pkg/plugins/resources/k8s/native/config/rbac/role.yaml
	deleted by them: pkg/plugins/resources/k8s/native/controllers/doc.go

```


To fix up this pull request, you can check it out locally. See documentation: https://docs.github.com/en/github/collaborating-with-pull-requests/reviewing-changes-in-pull-requests/checking-out-pull-requests-locally

---


<details>
<summary>Mergify commands and options</summary>

<br />

More conditions and actions can be found in the [documentation](https://docs.mergify.com/).

You can also trigger Mergify actions by commenting on this pull request:

- `@Mergifyio refresh` will re-evaluate the rules
- `@Mergifyio rebase` will rebase this PR on its base branch
- `@Mergifyio update` will merge the base branch into this PR
- `@Mergifyio backport <destination>` will backport this PR on `<destination>` branch

Additionally, on Mergify [dashboard](https://dashboard.mergify.com/) you can:

- look at your merge queues
- generate the Mergify configuration with the config editor.

Finally, you can contact us on https://mergify.com
</details>



Patch:
diff --git a/mk/check.mk b/mk/check.mk
index 864a9d9a3..f8fcd4ea9 100644
--- a/mk/check.mk
+++ b/mk/check.mk
@@ -40,5 +40,4 @@ ginkgo/unfocus:
 
 .PHONY: check
 check: generate fmt docs helm-lint golangci-lint tidy helm-docs ginkgo/unfocus ## Dev: Run code checks (go fmt, go vet, ...)
-	$(MAKE) generate manifests -C pkg/plugins/resources/k8s/native
 	git diff --quiet || test $$(git diff --name-only | grep -v -e 'go.mod$$' -e 'go.sum$$' | wc -l) -eq 0 || ( echo "The following changes (result of code generators and code checks) have been detected:" && git --no-pager diff && false ) # fail if Git working tree is dirty
diff --git a/mk/generate.mk b/mk/generate.mk
index b0c8bab9d..10c97253c 100644
--- a/mk/generate.mk
+++ b/mk/generate.mk
@@ -23,7 +23,7 @@ clean/proto: ## Dev: Remove auto-generated Protobuf files
 
 .PHONY: generate
 generate:  ## Dev: Run code generators
-generate: clean/proto generate/api protoc/pkg/config/app/kumactl/v1alpha1 protoc/pkg/test/apis/sample/v1alpha1 protoc/plugins resources/type generate/deepcopy
+generate: clean/proto generate/api protoc/pkg/config/app/kumactl/v1alpha1 protoc/pkg/test/apis/sample/v1alpha1 protoc/plugins resources/type generate/kubernetes
 
 .PHONY: resources/type
 resources/type:
@@ -64,8 +64,8 @@ generate/envoy-imports:
 	go list github.com/envoyproxy/go-control-plane/... | grep "github.com/envoyproxy/go-control-plane/envoy/" | awk '{printf "\t_ \"%s\"\n", $$1}' >> ${ENVOY_IMPORTS}
 	echo ')' >> ${ENVOY_IMPORTS}
 
-.PHONY: generate/deepcopy
-generate/deepcopy:
+.PHONY: generate/kubernetes
+generate/kubernetes:
 	$(MAKE) -C pkg/plugins/resources/k8s/native generate
 
 .PHONY: generate/api
diff --git a/pkg/plugins/resources/k8s/native/Makefile b/pkg/plugins/resources/k8s/native/Makefile
index 324f988ab..b5f277324 100644
--- a/pkg/plugins/resources/k8s/native/Makefile
+++ b/pkg/plugins/resources/k8s/native/Makefile
@@ -1,4 +1,4 @@
-.PHONY: all test install crd/install crd/uninstall crd/upgrade deploy manifests generate controller-gen
+.PHONY: all test install crd/install crd/uninstall crd/upgrade deploy generate controller-gen
 
 # TODO(yskopets): CRD generation is broken since introduction of .proto definitions
 # Produce CRDs that work back to Kubernetes 1.11 (no version conversion)
@@ -27,33 +27,28 @@ GO_TEST_OPTS ?=
 COVERAGE_PROFILE ?= cover.out
 
 # Run tests
-test: generate manifests
+test: generate
 	$(GO_TEST) $(GO_TEST_OPTS) -race -covermode=atomic -coverpkg=./... -coverprofile="$(COVERAGE_PROFILE)" ./api/... ./controllers/...
 
 # Install CRDs into a cluster
-install: manifests
-	kubectl apply -f config/crd/bases
+install: crd/install
 
-crd/install: ## Install CRDs into a cluster
+crd/install: generate ## Install CRDs into a cluster
 	kubectl apply -f config/crd/bases
 
-crd/uninstall: manifests ## Uninstall CRDs from a cluster
+crd/uninstall: generate ## Uninstall CRDs from a cluster
 	kubectl delete -f config/crd/bases
 
-crd/upgrade: manifests ## Upgrade CRDs in a cluster
+crd/upgrade: generate ## Upgrade CRDs in a cluster
 	kubectl diff -f config/crd/bases || kubectl apply -f config/crd/bases
 
 # Deploy controller in the configured Kubernetes cluster in ~/.kube/config
-deploy: manifests
+deploy: generate
 	kubectl apply -f config/crd/bases
 	kustomize build config/default | kubectl apply -f -
 
-# Generate manifests e.g. CRD, RBAC etc.
-manifests:
-	$(CONTROLLER_GEN) $(CRD_OPTIONS) rbac:roleName=manager-role webhook paths="./api/...;./controllers/..." $(CRD_OUTPUT)
-
-# Generate code
 generate:
+	$(CONTROLLER_GEN) $(CRD_OPTIONS) webhook paths="./api/..." $(CRD_OUTPUT)
 	$(CONTROLLER_GEN) object:headerFile=./hack/boilerplate.go.txt,year=$$(date +%Y) paths=./api/...
 
 help: ## Display this help screen
diff --git a/pkg/plugins/resources/k8s/native/config/rbac/auth_proxy_role.yaml b/pkg/plugins/resources/k8s/native/config/rbac/auth_proxy_role.yaml
deleted file mode 100644
index 618f5e417..000000000
--- a/pkg/plugins/resources/k8s/native/config/rbac/auth_proxy_role.yaml
+++ /dev/null
@@ -1,13 +0,0 @@
-apiVersion: rbac.authorization.k8s.io/v1
-kind: ClusterRole
-metadata:
-  name: proxy-role
-rules:
-- apiGroups: ["authentication.k8s.io"]
-  resources:
-  - tokenreviews
-  verbs: ["create"]
-- apiGroups: ["authorization.k8s.io"]
-  resources:
-  - subjectaccessreviews
-  verbs: ["create"]
diff --git a/pkg/plugins/resources/k8s/native/config/rbac/auth_proxy_role_binding.yaml b/pkg/plugins/resources/k8s/native/config/rbac/auth_proxy_role_binding.yaml
deleted file mode 100644
index 59123e779..000000000
--- a/pkg/plugins/resources/k8s/native/config/rbac/auth_proxy_role_binding.yaml
+++ /dev/null
@@ -1,12 +0,0 @@
-apiVersion: rbac.authorization.k8s.io/v1
-kind: ClusterRoleBinding
-metadata:
-  name: proxy-rolebinding
-roleRef:
-  apiGroup: rbac.authorization.k8s.io
-  kind: ClusterRole
-  name: proxy-role
-subjects:
-- kind: ServiceAccount
-  name: default
-  namespace: kuma-system
diff --git a/pkg/plugins/resources/k8s/native/config/rbac/auth_proxy_service.yaml b/pkg/plugins/resources/k8s/native/config/rbac/auth_proxy_service.yaml
deleted file mode 100644
index 8df6da639..000000000
--- a/pkg/plugins/resources/k8s/native/config/rbac/auth_proxy_service.yaml
+++ /dev/null
@@ -1,20 +0,0 @@
-apiVersion: v1
-kind: Service
-metadata:
-  annotations:
-    prometheus.io/port: "8443"
-    prometheus.io/scheme: https
-    prometheus.io/scrape: "true"
-  labels:
-    control-plane: controller-manager
-    controller-tools.k8s.io: "1.0"
-  name: controller-manager-metrics-service
-  namespace: kuma-system
-spec:
-  ports:
-  - name: https
-    port: 8443
-    targetPort: https
-  selector:
-    control-plane: controller-manager
-    controller-tools.k8s.io: "1.0"
diff --git a/pkg/plugins/resources/k8s/native/config/rbac/kustomization.yaml b/pkg/plugins/resources/k8s/native/config/rbac/kustomization.yaml
deleted file mode 100644
index 1e9398063..000000000
--- a/pkg/plugins/resources/k8s/native/config/rbac/kustomization.yaml
+++ /dev/null
@@ -1,9 +0,0 @@
-resources:
-- role.yaml
-- role_binding.yaml
-# Comment the following 3 lines if you want to disable
-# the auth proxy (https://github.com/brancz/kube-rbac-proxy)
-# which protects your /metrics endpoint.
-#- auth_proxy_service.yaml
-#- auth_proxy_role.yaml
-#- auth_proxy_role_binding.yaml
diff --git a/pkg/plugins/resources/k8s/native/config/rbac/role_binding.yaml b/pkg/plugins/resources/k8s/native/config/rbac/role_binding.yaml
deleted file mode 100644
index a527ddb4a..000000000
--- a/pkg/plugins/resources/k8s/native/config/rbac/role_binding.yaml
+++ /dev/null
@@ -1,12 +0,0 @@
-apiVersion: rbac.authorization.k8s.io/v1
-kind: ClusterRoleBinding
-metadata:
-  name: manager-rolebinding
-roleRef:
-  apiGroup: rbac.authorization.k8s.io
-  kind: ClusterRole
-  name: manager-role
-subjects:
-- kind: ServiceAccount
-  name: default
-  namespace: kuma-system


Test patch:
diff --git a/pkg/plugins/resources/k8s/native/controllers/suite_test.go b/pkg/plugins/resources/k8s/native/controllers/suite_test.go
deleted file mode 100644
index 5cb2be5df..000000000
--- a/pkg/plugins/resources/k8s/native/controllers/suite_test.go
+++ /dev/null
@@ -1,68 +0,0 @@
-/*
-Copyright 2019 Kuma authors.
-
-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 controllers
-
-import (
-	"path/filepath"
-	"testing"
-	"time"
-
-	. "github.com/onsi/ginkgo"
-	. "github.com/onsi/gomega"
-	"k8s.io/client-go/kubernetes/scheme"
-	"sigs.k8s.io/controller-runtime/pkg/client"
-	"sigs.k8s.io/controller-runtime/pkg/envtest"
-
-	meshv1alpha1 "github.com/kumahq/kuma/pkg/plugins/resources/k8s/native/api/v1alpha1"
-	"github.com/kumahq/kuma/pkg/test"
-)
-
-var k8sClient client.Client
-var testEnv *envtest.Environment
-
-func TestAPIs(t *testing.T) {
-	test.RunSpecs(t, "Controller Suite")
-}
-
-var _ = BeforeSuite(test.Within(time.Minute, func() {
-	By("bootstrapping test environment")
-	testEnv = &envtest.Environment{
-		CRDDirectoryPaths: []string{filepath.Join("..", "config", "crd", "bases")},
-	}
-
-	cfg, err := testEnv.Start()
-	Expect(err).ToNot(HaveOccurred())
-	Expect(cfg).ToNot(BeNil())
-
-	err = meshv1alpha1.AddToScheme(scheme.Scheme)
-	Expect(err).NotTo(HaveOccurred())
-
-	err = meshv1alpha1.AddToScheme(scheme.Scheme)
-	Expect(err).NotTo(HaveOccurred())
-
-	// +kubebuilder:scaffold:scheme
-
-	k8sClient, err = client.New(cfg, client.Options{Scheme: scheme.Scheme})
-	Expect(err).ToNot(HaveOccurred())
-	Expect(k8sClient).ToNot(BeNil())
-}))
-
-var _ = AfterSuite(func() {
-	By("tearing down the test environment")
-	err := testEnv.Stop()
-	Expect(err).ToNot(HaveOccurred())
-})