-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ansible/helm - apply the service account (#4653)
**Description of the change:** - create and bind to a non-default service account - follow up : kubernetes-sigs/kubebuilder#2070 and #4626 **Motivation for the change:** - fix: Scorecard docs instructions are wrong now for Ansible/Helm - rfe: apply the same go behaviour of Go default config for Ansible/Helm - Reduce the complexities for we address kubernetes-sigs/kubebuilder#2015 - Keep Ansible/Helm/Go aligned (Align Helm/Ansible plugins with the changes made for Golang ( go/v3 )) Closes: #4644
- Loading branch information
1 parent
23d4794
commit c929783
Showing
39 changed files
with
312 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
# entries is a list of entries to include in | ||
# release notes and/or the migration guide | ||
entries: | ||
- description: > | ||
(ansible/v1, helm/v1) Create and bind to a non-default service account ([kubebuilder#2070](https://github.com/kubernetes-sigs/kubebuilder/pull/2070)) | ||
kind: "addition" | ||
breaking: false | ||
# NOTE: ONLY USE `pull_request_override` WHEN ADDING THIS | ||
# FILE FOR A PREVIOUSLY MERGED PULL_REQUEST! | ||
# | ||
# The generator auto-detects the PR number from the commit | ||
# message in which this file was originally added. | ||
# | ||
# What is the pull request number (without the "#")? | ||
# pull_request_override: 0 | ||
# Migration can be defined to automatically add a section to | ||
# the migration guide. This is required for breaking changes. | ||
migration: | ||
header: (ansible/v1, helm/v1) Add a `system:controller-manager` ServiceAccount to your project. | ||
body: > | ||
A non-default ServiceAccount `controller-manager` is scaffolded on `operator-sdk init`, | ||
to improve security for operators installed in shared namespaces. To add this ServiceAccount | ||
to your project, do the following: | ||
```sh | ||
# Create the ServiceAccount. | ||
cat <<EOF > config/rbac/service_account.yaml | ||
apiVersion: v1 | ||
kind: ServiceAccount | ||
metadata: | ||
name: controller-manager | ||
namespace: system | ||
EOF | ||
# Add it to the list of RBAC resources. | ||
echo "- service_account.yaml" >> config/rbac/kustomization.yaml | ||
# Update all RoleBinding and ClusterRoleBinding subjects that reference the operator's ServiceAccount. | ||
find config/rbac -name *_binding.yaml -exec sed -i -E 's/ name: default/ name: controller-manager/g' {} \; | ||
# Add the ServiceAccount name to the manager Deployment's spec.template.spec.serviceAccountName. | ||
sed -i -E 's/([ ]+)(terminationGracePeriodSeconds:)/\1serviceAccountName: controller-manager\n\1\2/g' config/manager/manager.yaml | ||
``` | ||
The changes should look like: | ||
```diff | ||
# config/manager/manager.yaml | ||
requests: | ||
cpu: 100m | ||
memory: 20Mi | ||
+ serviceAccountName: controller-manager | ||
terminationGracePeriodSeconds: 10 | ||
# config/rbac/auth_proxy_role_binding.yaml | ||
name: proxy-role | ||
subjects: | ||
- kind: ServiceAccount | ||
- name: default | ||
+ name: controller-manager | ||
namespace: system | ||
# config/rbac/kustomization.yaml | ||
resources: | ||
+- service_account.yaml | ||
- role.yaml | ||
- role_binding.yaml | ||
- leader_election_role.yaml | ||
# config/rbac/leader_election_role_binding.yaml | ||
name: leader-election-role | ||
subjects: | ||
- kind: ServiceAccount | ||
- name: default | ||
+ name: controller-manager | ||
namespace: system | ||
# config/rbac/role_binding.yaml | ||
name: manager-role | ||
subjects: | ||
- kind: ServiceAccount | ||
- name: default | ||
+ name: controller-manager | ||
namespace: system | ||
# config/rbac/service_account.yaml | ||
+apiVersion: v1 | ||
+kind: ServiceAccount | ||
+metadata: | ||
+ name: controller-manager | ||
+ namespace: system | ||
``` | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
internal/plugins/ansible/v1/scaffolds/internal/templates/config/rbac/service_account.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
Copyright 2020 The Kubernetes 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 rbac | ||
|
||
import ( | ||
"path/filepath" | ||
|
||
"sigs.k8s.io/kubebuilder/v3/pkg/model/file" | ||
) | ||
|
||
var _ file.Template = &ServiceAccount{} | ||
|
||
// ServiceAccount scaffolds a file that defines the service account the manager is deployed in. | ||
type ServiceAccount struct { | ||
file.TemplateMixin | ||
} | ||
|
||
// SetTemplateDefaults implements file.Template | ||
func (f *ServiceAccount) SetTemplateDefaults() error { | ||
if f.Path == "" { | ||
f.Path = filepath.Join("config", "rbac", "service_account.yaml") | ||
} | ||
|
||
f.TemplateBody = serviceAccountTemplate | ||
|
||
return nil | ||
} | ||
|
||
const serviceAccountTemplate = `apiVersion: v1 | ||
kind: ServiceAccount | ||
metadata: | ||
name: controller-manager | ||
namespace: system | ||
` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
internal/plugins/helm/v1/scaffolds/internal/templates/config/rbac/service_account.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
Copyright 2020 The Kubernetes 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 rbac | ||
|
||
import ( | ||
"path/filepath" | ||
|
||
"sigs.k8s.io/kubebuilder/v3/pkg/model/file" | ||
) | ||
|
||
var _ file.Template = &ServiceAccount{} | ||
|
||
// ServiceAccount scaffolds a file that defines the service account the manager is deployed in. | ||
type ServiceAccount struct { | ||
file.TemplateMixin | ||
} | ||
|
||
// SetTemplateDefaults implements file.Template | ||
func (f *ServiceAccount) SetTemplateDefaults() error { | ||
if f.Path == "" { | ||
f.Path = filepath.Join("config", "rbac", "service_account.yaml") | ||
} | ||
|
||
f.TemplateBody = serviceAccountTemplate | ||
|
||
return nil | ||
} | ||
|
||
const serviceAccountTemplate = `apiVersion: v1 | ||
kind: ServiceAccount | ||
metadata: | ||
name: controller-manager | ||
namespace: system | ||
` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.