Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Backport to 5.17] Fix serviceAccount for noobaa-core #1431

Merged
merged 2 commits into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 1 addition & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -177,15 +177,7 @@ golangci-lint: gen
.PHONY: golangci-lint

lint: gen
GO111MODULE=off go get -u -a golang.org/x/lint/golint
GO111MODULE=off go install -a golang.org/x/lint/golint
GO111MODULE=off go run golang.org/x/lint/golint \
-set_exit_status=1 \
$$(go list ./... | cut -d'/' -f5- | sed 's/^\(.*\)$$/\.\/\1\//' | grep -v ./pkg/apis/noobaa/v1alpha1/ | grep -v ./pkg/bundle/)
@echo
GO111MODULE=off go run golang.org/x/lint/golint \
-set_exit_status=1 \
$$(echo ./pkg/apis/noobaa/v1alpha1/* | tr ' ' '\n' | grep -v '/zz_generated')
@echo "Lint is deprecated and failing due to a dependency. Disabling it as a quick fix to release the CI flow."
@echo "✅ lint"
.PHONY: lint

Expand Down
4 changes: 2 additions & 2 deletions deploy/role_binding_core.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: noobaa-core-role-binding
name: noobaa-core
namespace: openshift-storage
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: Role
name: noobaa-core-role
name: noobaa-core
subjects:
- kind: ServiceAccount
name: noobaa-core
Expand Down
2 changes: 1 addition & 1 deletion deploy/role_core.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: noobaa-core-role
name: noobaa-core
rules:
- apiGroups:
- noobaa.io
Expand Down
10 changes: 5 additions & 5 deletions pkg/bundle/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -6310,17 +6310,17 @@ subjects:
name: custom-metrics-prometheus-adapter
`

const Sha256_deploy_role_binding_core_yaml = "8e6063e6056d180419063b17d364596a554140bcdb93c521e031f940e9377bb3"
const Sha256_deploy_role_binding_core_yaml = "99b90a402f770a4c3e7b1bb36c4e9175341f1697ff68a8ff3b121b43ef4d69d5"

const File_deploy_role_binding_core_yaml = `apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: noobaa-core-role-binding
name: noobaa-core
namespace: openshift-storage
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: Role
name: noobaa-core-role
name: noobaa-core
subjects:
- kind: ServiceAccount
name: noobaa-core
Expand Down Expand Up @@ -6391,12 +6391,12 @@ subjects:
name: custom-metrics-prometheus-adapter
`

const Sha256_deploy_role_core_yaml = "fad0d6b3353f8b2dbbc5bf55f99885917506982ba89c5556727d2047fa95477a"
const Sha256_deploy_role_core_yaml = "c3cfb5b87298224fd6e4e4bff32d3948ad168a0110b8569118a260739ef5d5e7"

const File_deploy_role_core_yaml = `apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: noobaa-core-role
name: noobaa-core
rules:
- apiGroups:
- noobaa.io
Expand Down
30 changes: 25 additions & 5 deletions pkg/operator/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,13 @@ func RunUpgrade(cmd *cobra.Command, args []string) {
c := LoadOperatorConf(cmd)
util.KubeApply(c.NS)
util.KubeApply(c.SA)
util.KubeApply(c.SACore)
util.KubeApply(c.SAEndpoint)
util.KubeApply(c.Role)
util.KubeApply(c.RoleCore)
util.KubeApply(c.RoleEndpoint)
util.KubeApply(c.RoleBinding)
util.KubeApply(c.RoleBindingCore)
util.KubeApply(c.RoleBindingEndpoint)
util.KubeApply(c.ClusterRole)
util.KubeApply(c.ClusterRoleBinding)
Expand Down Expand Up @@ -168,10 +171,13 @@ func RunInstall(cmd *cobra.Command, args []string) {
c := LoadOperatorConf(cmd)
util.KubeCreateSkipExisting(c.NS)
util.KubeCreateSkipExisting(c.SA)
util.KubeCreateSkipExisting(c.SACore)
util.KubeCreateSkipExisting(c.SAEndpoint)
util.KubeCreateSkipExisting(c.Role)
util.KubeCreateSkipExisting(c.RoleCore)
util.KubeCreateSkipExisting(c.RoleEndpoint)
util.KubeCreateSkipExisting(c.RoleBinding)
util.KubeCreateSkipExisting(c.RoleBindingCore)
util.KubeCreateSkipExisting(c.RoleBindingEndpoint)
util.KubeCreateSkipExisting(c.ClusterRole)
util.KubeCreateSkipExisting(c.ClusterRoleBinding)
Expand Down Expand Up @@ -266,10 +272,13 @@ func RunUninstall(cmd *cobra.Command, args []string) {
util.KubeDelete(c.ClusterRoleBinding)
util.KubeDelete(c.ClusterRole)
util.KubeDelete(c.RoleBindingEndpoint)
util.KubeDelete(c.RoleBindingCore)
util.KubeDelete(c.RoleBinding)
util.KubeDelete(c.RoleEndpoint)
util.KubeDelete(c.RoleCore)
util.KubeDelete(c.Role)
util.KubeDelete(c.SAEndpoint)
util.KubeDelete(c.SACore)
util.KubeDelete(c.SA)
} else {
log.Printf("Operator Delete: currently disabled with \"--no-deploy\" flag")
Expand Down Expand Up @@ -305,15 +314,17 @@ func RunStatus(cmd *cobra.Command, args []string) {
c := LoadOperatorConf(cmd)
LoadAdmissionConf(c)
util.KubeCheck(c.NS)
if util.KubeCheck(c.SA) && util.KubeCheck(c.SAEndpoint) {
if util.KubeCheck(c.SA) && util.KubeCheck(c.SAEndpoint) && util.KubeCheck(c.SACore) {
// in OLM deployment the roles and bindings have generated names
// so we list and lookup bindings to our service account to discover the actual names
DetectRole(c)
DetectClusterRole(c)
}
util.KubeCheck(c.Role)
util.KubeCheck(c.RoleBinding)
util.KubeCheck(c.RoleCore)
util.KubeCheck(c.RoleEndpoint)
util.KubeCheck(c.RoleBinding)
util.KubeCheck(c.RoleBindingCore)
util.KubeCheck(c.RoleBindingEndpoint)
util.KubeCheck(c.ClusterRole)
util.KubeCheck(c.ClusterRoleBinding)
Expand All @@ -334,8 +345,11 @@ func RunYaml(cmd *cobra.Command, args []string) {
util.Panic(p.PrintObj(c.SA, os.Stdout))
util.Panic(p.PrintObj(c.Role, os.Stdout))
util.Panic(p.PrintObj(c.RoleBinding, os.Stdout))
util.Panic(p.PrintObj(c.SACore, os.Stdout))
util.Panic(p.PrintObj(c.SAEndpoint, os.Stdout))
util.Panic(p.PrintObj(c.RoleCore, os.Stdout))
util.Panic(p.PrintObj(c.RoleEndpoint, os.Stdout))
util.Panic(p.PrintObj(c.RoleBindingCore, os.Stdout))
util.Panic(p.PrintObj(c.RoleBindingEndpoint, os.Stdout))
util.Panic(p.PrintObj(c.ClusterRole, os.Stdout))
util.Panic(p.PrintObj(c.ClusterRoleBinding, os.Stdout))
Expand Down Expand Up @@ -373,16 +387,16 @@ func LoadOperatorConf(cmd *cobra.Command) *Conf {

c.NS = util.KubeObject(bundle.File_deploy_namespace_yaml).(*corev1.Namespace)
c.SA = util.KubeObject(bundle.File_deploy_service_account_yaml).(*corev1.ServiceAccount)
c.SAEndpoint = util.KubeObject(bundle.File_deploy_service_account_endpoint_yaml).(*corev1.ServiceAccount)
c.SACore = util.KubeObject(bundle.File_deploy_service_account_core_yaml).(*corev1.ServiceAccount)
c.SAEndpoint = util.KubeObject(bundle.File_deploy_service_account_endpoint_yaml).(*corev1.ServiceAccount)
c.SAUI = util.KubeObject(bundle.File_deploy_service_account_ui_yaml).(*corev1.ServiceAccount)
c.Role = util.KubeObject(bundle.File_deploy_role_yaml).(*rbacv1.Role)
c.RoleEndpoint = util.KubeObject(bundle.File_deploy_role_endpoint_yaml).(*rbacv1.Role)
c.RoleCore = util.KubeObject(bundle.File_deploy_role_core_yaml).(*rbacv1.Role)
c.RoleEndpoint = util.KubeObject(bundle.File_deploy_role_endpoint_yaml).(*rbacv1.Role)
c.RoleUI = util.KubeObject(bundle.File_deploy_role_ui_yaml).(*rbacv1.ClusterRole)
c.RoleBinding = util.KubeObject(bundle.File_deploy_role_binding_yaml).(*rbacv1.RoleBinding)
c.RoleBindingEndpoint = util.KubeObject(bundle.File_deploy_role_binding_endpoint_yaml).(*rbacv1.RoleBinding)
c.RoleBindingCore = util.KubeObject(bundle.File_deploy_role_binding_core_yaml).(*rbacv1.RoleBinding)
c.RoleBindingEndpoint = util.KubeObject(bundle.File_deploy_role_binding_endpoint_yaml).(*rbacv1.RoleBinding)
c.ClusterRole = util.KubeObject(bundle.File_deploy_cluster_role_yaml).(*rbacv1.ClusterRole)
c.ClusterRoleBinding = util.KubeObject(bundle.File_deploy_cluster_role_binding_yaml).(*rbacv1.ClusterRoleBinding)
c.Deployment = util.KubeObject(bundle.File_deploy_operator_yaml).(*appsv1.Deployment)
Expand Down Expand Up @@ -445,6 +459,12 @@ func DetectRole(c *Conf) {
c.RoleEndpoint.Name = b.RoleRef.Name
c.RoleBindingEndpoint.Name = b.Name
}
if s.Kind == "ServiceAccount" &&
s.Name == c.SACore.Name &&
s.Namespace == c.SACore.Namespace {
c.RoleCore.Name = b.RoleRef.Name
c.RoleBindingCore.Name = b.Name
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/system/phase2_creating.go
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ func (r *Reconciler) SetDesiredCoreApp() error {
r.CoreApp.Spec.ServiceName = r.ServiceMgmt.Name

podSpec := &r.CoreApp.Spec.Template.Spec
podSpec.ServiceAccountName = "noobaa"
podSpec.ServiceAccountName = "noobaa-core"
coreImageChanged := false

// adding the missing Volumes from default podSpec
Expand Down
Loading