Skip to content

Commit 8d08130

Browse files
refactor: use controller-gen for rbac in poddefaults-webhook (#215)
Signed-off-by: Mathew Wicks <5735406+thesuperzapper@users.noreply.github.com>
1 parent c1c76ae commit 8d08130

File tree

7 files changed

+43
-21
lines changed

7 files changed

+43
-21
lines changed

components/poddefaults-webhooks/Makefile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@ endif
1414

1515
.PHONY: manifests
1616
manifests: controller-gen ## Generate CustomResourceDefinition objects.
17-
$(CONTROLLER_GEN) crd paths="./..." \
18-
output:crd:artifacts:config=manifests/kustomize/base
17+
$(CONTROLLER_GEN) rbac:roleName=poddefaults-webhook-cluster-role crd paths="./..." \
18+
output:crd:artifacts:config=manifests/kustomize/base \
19+
output:rbac:artifacts:config=manifests/kustomize/base
1920

2021
mv manifests/kustomize/base/kubeflow.org_poddefaults.yaml manifests/kustomize/base/crd.yaml
2122

components/poddefaults-webhooks/main.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ import (
4242
"k8s.io/klog"
4343
)
4444

45+
// +kubebuilder:rbac:groups=kubeflow.org,resources=poddefaults,verbs=create;delete;get;list;patch;update;watch
46+
4547
const (
4648
annotationPrefix = "poddefault.admission.kubeflow.org"
4749
istioProxyContainerName = "istio-proxy"

components/poddefaults-webhooks/manifests/kustomize/base/crd.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4561,3 +4561,5 @@ spec:
45614561
type: object
45624562
served: true
45634563
storage: true
4564+
subresources:
4565+
status: {}

components/poddefaults-webhooks/manifests/kustomize/base/kustomization.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ kind: Kustomization
44
namespace: kubeflow
55

66
resources:
7-
- cluster-role-binding.yaml
8-
- cluster-role.yaml
97
- crd.yaml
108
- deployment.yaml
119
- mutating-webhook-configuration.yaml
10+
- role.yaml
11+
- role_binding.yaml
1212
- service-account.yaml
1313
- service.yaml
1414
- user_cluster_roles.yaml

components/poddefaults-webhooks/manifests/kustomize/base/cluster-role.yaml renamed to components/poddefaults-webhooks/manifests/kustomize/base/role.yaml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
---
12
apiVersion: rbac.authorization.k8s.io/v1
23
kind: ClusterRole
34
metadata:
@@ -8,10 +9,10 @@ rules:
89
resources:
910
- poddefaults
1011
verbs:
12+
- create
13+
- delete
1114
- get
12-
- watch
1315
- list
14-
- update
15-
- create
1616
- patch
17-
- delete
17+
- update
18+
- watch

components/poddefaults-webhooks/manifests/kustomize/base/cluster-role-binding.yaml renamed to components/poddefaults-webhooks/manifests/kustomize/base/role_binding.yaml

File renamed without changes.

components/poddefaults-webhooks/pkg/apis/settings/v1alpha1/poddefault_types.go

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,16 @@ import (
2020
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2121
)
2222

23-
// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
24-
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.
23+
// Important: Run "make" to regenerate code after modifying this file
24+
25+
/*
26+
===============================================================================
27+
PodDefault - Spec
28+
===============================================================================
29+
*/
2530

2631
// PodDefaultSpec defines the desired state of PodDefault
2732
type PodDefaultSpec struct {
28-
// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
29-
// Important: Run "make" to regenerate code after modifying this file
3033

3134
// Selector is a label query over a set of resources, in this case pods.
3235
// Required.
@@ -88,21 +91,28 @@ type PodDefaultSpec struct {
8891
ImagePullSecrets []v1.LocalObjectReference `json:"imagePullSecrets,omitempty"`
8992
}
9093

94+
/*
95+
===============================================================================
96+
PodDefault - Status
97+
===============================================================================
98+
*/
99+
91100
// PodDefaultStatus defines the observed state of PodDefault
92101
type PodDefaultStatus struct {
93102
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
94-
// Important: Run "make" to regenerate code after modifying this file
95103
}
96104

97-
// +genclient
98-
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
105+
/*
106+
===============================================================================
107+
PodDefault
108+
===============================================================================
109+
*/
110+
111+
// +kubebuilder:object:root=true
112+
// +kubebuilder:resource:path=poddefaults
113+
// +kubebuilder:subresource:status
99114

100115
// PodDefault is the Schema for the poddefaults API
101-
// +k8s:openapi-gen=true
102-
// +kubebuilder:resource:path=poddefaults
103-
// +kubebuilder:rbac:groups=apps,resources=deployments,verbs=get;watch;list;update
104-
// +kubebuilder:rbac:groups=,resources=events,verbs=create;patch;update
105-
// +kubebuilder:informers:group=apps,version=v1,kind=Deployment
106116
type PodDefault struct {
107117
metav1.TypeMeta `json:",inline"`
108118
metav1.ObjectMeta `json:"metadata,omitempty"`
@@ -111,7 +121,13 @@ type PodDefault struct {
111121
Status PodDefaultStatus `json:"status,omitempty"`
112122
}
113123

114-
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
124+
/*
125+
===============================================================================
126+
PodDefaultList
127+
===============================================================================
128+
*/
129+
130+
// +kubebuilder:object:root=true
115131

116132
// PodDefaultList contains a list of PodDefault
117133
type PodDefaultList struct {

0 commit comments

Comments
 (0)