Skip to content

Commit

Permalink
Replace current ServiceAccount used in pods under test (#47)
Browse files Browse the repository at this point in the history
* Replace current ServiceAccount used in pods under test

* Allow creation of the resources we want to include in this change
  • Loading branch information
ramperher authored Feb 9, 2024
1 parent ebd89f2 commit 0ddfda3
Show file tree
Hide file tree
Showing 23 changed files with 680 additions and 9 deletions.
29 changes: 29 additions & 0 deletions testpmd-lb-operator/config/rbac/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,33 @@ rules:
- privileged
verbs:
- use
##
## Rules to allow the creation of ServiceAccount, Role and RoleBinding
## for the pods deployed by this operator
##
- apiGroups:
- ""
resources:
- serviceaccounts
verbs:
- create
- delete
- get
- list
- patch
- update
- watch
- apiGroups:
- "rbac.authorization.k8s.io"
resources:
- roles
- rolebindings
verbs:
- create
- delete
- get
- list
- patch
- update
- watch
# +kubebuilder:scaffold:rules
15 changes: 15 additions & 0 deletions testpmd-lb-operator/roles/loadbalancer/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,21 @@
loop_control:
loop_var: network_item

- name: Create ServiceAccount for LoadBalancer resource
k8s:
state: present
definition: "{{ lookup('template', 'service_account.yml') }}"

- name: Create Role for LoadBalancer resource
k8s:
state: present
definition: "{{ lookup('template', 'role.yml') }}"

- name: Create RoleBinding for LoadBalancer resource
k8s:
state: present
definition: "{{ lookup('template', 'role_binding.yml') }}"

- name: Create LoadBalancer deployment
k8s:
state: present
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ spec:
- cnf-app
- pkt-gen
topologyKey: kubernetes.io/hostname
serviceAccountName: testpmd-lb-operator-controller-manager
serviceAccountName: loadbalancer-account
{% if numa_aware_topology is defined and numa_aware_topology | length %}
schedulerName: "{{ numa_aware_topology }}"
{% endif %}
Expand Down
82 changes: 82 additions & 0 deletions testpmd-lb-operator/roles/loadbalancer/templates/role.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
---
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: loadbalancer-role
namespace: example-cnf
rules:
##
## Base operator rules
##
- apiGroups:
- ""
resources:
- secrets
- pods
- pods/exec
- pods/log
verbs:
- create
- delete
- get
- list
- patch
- update
- watch
- apiGroups:
- apps
resources:
- deployments
- daemonsets
- replicasets
- statefulsets
verbs:
- create
- delete
- get
- list
- patch
- update
- watch
##
## Rules for examplecnf.openshift.io/v1, Kind: LoadBalancer
##
- apiGroups:
- examplecnf.openshift.io
resources:
- loadbalancers
- loadbalancers/status
- loadbalancers/finalizers
verbs:
- create
- delete
- get
- list
- patch
- update
- watch
- apiGroups:
- examplecnf.openshift.io
resources:
- cnfappmacs
verbs:
- get
- list
- watch
- apiGroups:
- k8s.cni.cncf.io
resources:
- network-attachment-definitions
verbs:
- get
- list
- watch
- apiGroups:
- security.openshift.io
resources:
- securitycontextconstraints
resourceNames:
- privileged
verbs:
- use
# +kubebuilder:scaffold:rules
14 changes: 14 additions & 0 deletions testpmd-lb-operator/roles/loadbalancer/templates/role_binding.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: loadbalancer-rolebinding
namespace: example-cnf
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: Role
name: loadbalancer-role
subjects:
- kind: ServiceAccount
name: loadbalancer-account
namespace: example-cnf
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: loadbalancer-account
namespace: example-cnf
29 changes: 29 additions & 0 deletions testpmd-operator/config/rbac/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,33 @@ rules:
- privileged
verbs:
- use
##
## Rules to allow the creation of ServiceAccount, Role and RoleBinding
## for the pods deployed by this operator
##
- apiGroups:
- ""
resources:
- serviceaccounts
verbs:
- create
- delete
- get
- list
- patch
- update
- watch
- apiGroups:
- "rbac.authorization.k8s.io"
resources:
- roles
- rolebindings
verbs:
- create
- delete
- get
- list
- patch
- update
- watch
# +kubebuilder:scaffold:rules
15 changes: 15 additions & 0 deletions testpmd-operator/roles/testpmd/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,21 @@
debug:
var: network_resources

- name: Create ServiceAccount for TestPMD resource
k8s:
state: present
definition: "{{ lookup('template', 'service_account.yml') }}"

- name: Create Role for TestPMD resource
k8s:
state: present
definition: "{{ lookup('template', 'role.yml') }}"

- name: Create RoleBinding for TestPMD resource
k8s:
state: present
definition: "{{ lookup('template', 'role_binding.yml') }}"

- name: Create TestPMD deployment
community.kubernetes.k8s:
state: present
Expand Down
2 changes: 1 addition & 1 deletion testpmd-operator/roles/testpmd/templates/deployment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ spec:
values:
- lb-app
topologyKey: kubernetes.io/hostname
serviceAccountName: testpmd-operator-controller-manager
serviceAccountName: testpmd-account
{% if high_perf_runtime is defined and high_perf_runtime|length %}
runtimeClassName: "{{ high_perf_runtime }}"
{% endif %}
Expand Down
74 changes: 74 additions & 0 deletions testpmd-operator/roles/testpmd/templates/role.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
---
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: testpmd-role
namespace: example-cnf
rules:
##
## Base operator rules
##
- apiGroups:
- ""
resources:
- secrets
- pods
- pods/exec
- pods/log
- configmaps
verbs:
- create
- delete
- get
- list
- patch
- update
- watch
- apiGroups:
- apps
resources:
- deployments
- daemonsets
- replicasets
- statefulsets
verbs:
- create
- delete
- get
- list
- patch
- update
- watch
##
## Rules for examplecnf.openshift.io/v1, Kind: TestPMD
##
- apiGroups:
- examplecnf.openshift.io
resources:
- testpmds
- testpmds/status
verbs:
- create
- delete
- get
- list
- patch
- update
- watch
- apiGroups:
- k8s.cni.cncf.io
resources:
- network-attachment-definitions
verbs:
- get
- list
- watch
- apiGroups:
- security.openshift.io
resources:
- securitycontextconstraints
resourceNames:
- privileged
verbs:
- use
# +kubebuilder:scaffold:rules
14 changes: 14 additions & 0 deletions testpmd-operator/roles/testpmd/templates/role_binding.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: testpmd-rolebinding
namespace: example-cnf
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: Role
name: testpmd-role
subjects:
- kind: ServiceAccount
name: testpmd-account
namespace: example-cnf
6 changes: 6 additions & 0 deletions testpmd-operator/roles/testpmd/templates/service_account.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: testpmd-account
namespace: example-cnf
29 changes: 29 additions & 0 deletions trex-operator/config/rbac/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -139,4 +139,33 @@ rules:
- get
- list
- watch
##
## Rules to allow the creation of ServiceAccount, Role and RoleBinding
## for the pods deployed by this operator
##
- apiGroups:
- ""
resources:
- serviceaccounts
verbs:
- create
- delete
- get
- list
- patch
- update
- watch
- apiGroups:
- "rbac.authorization.k8s.io"
resources:
- roles
- rolebindings
verbs:
- create
- delete
- get
- list
- patch
- update
- watch
# +kubebuilder:scaffold:rules
27 changes: 22 additions & 5 deletions trex-operator/roles/app/tasks/job-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,25 @@
when:
- "'failed' not in item.status or item.status.failed != 1"

- name: create trexapp job
k8s:
state: present
definition: "{{ lookup('template', 'job.yml') }}"
when: "active_jobs|int == 0"
- name: trexapp job creation
when: "active_jobs|int == 0"
block:
- name: Create ServiceAccount for trexapp job resource
k8s:
state: present
definition: "{{ lookup('template', 'service_account.yml') }}"

- name: Create Role for trexapp job resource
k8s:
state: present
definition: "{{ lookup('template', 'role.yml') }}"

- name: Create RoleBinding for trexapp job resource
k8s:
state: present
definition: "{{ lookup('template', 'role_binding.yml') }}"

- name: create trexapp job
k8s:
state: present
definition: "{{ lookup('template', 'job.yml') }}"
Loading

0 comments on commit 0ddfda3

Please sign in to comment.