|
| 1 | +package resource |
| 2 | + |
| 3 | +import ( |
| 4 | + "context" |
| 5 | + |
| 6 | + rbacapi "k8s.io/api/rbac/v1" |
| 7 | + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" |
| 8 | + "k8s.io/apimachinery/pkg/runtime" |
| 9 | + rbacset "k8s.io/client-go/kubernetes/typed/rbac/v1" |
| 10 | + rbaclisters "k8s.io/client-go/listers/rbac/v1" |
| 11 | +) |
| 12 | + |
| 13 | +var _ Mutator = &generatorPrunerClusterRole{} |
| 14 | + |
| 15 | +type generatorPrunerClusterRole struct { |
| 16 | + lister rbaclisters.ClusterRoleLister |
| 17 | + client rbacset.RbacV1Interface |
| 18 | +} |
| 19 | + |
| 20 | +func newGeneratorPrunerClusterRole(lister rbaclisters.ClusterRoleLister, client rbacset.RbacV1Interface) *generatorPrunerClusterRole { |
| 21 | + return &generatorPrunerClusterRole{ |
| 22 | + lister: lister, |
| 23 | + client: client, |
| 24 | + } |
| 25 | +} |
| 26 | + |
| 27 | +func (gcr *generatorPrunerClusterRole) Type() runtime.Object { |
| 28 | + return &rbacapi.ClusterRole{} |
| 29 | +} |
| 30 | + |
| 31 | +func (gcr *generatorPrunerClusterRole) GetNamespace() string { |
| 32 | + return "" |
| 33 | +} |
| 34 | + |
| 35 | +func (gcr *generatorPrunerClusterRole) GetName() string { |
| 36 | + return "system:image-pruner" |
| 37 | +} |
| 38 | + |
| 39 | +func (gcr *generatorPrunerClusterRole) expected() (runtime.Object, error) { |
| 40 | + role := &rbacapi.ClusterRole{ |
| 41 | + ObjectMeta: metav1.ObjectMeta{ |
| 42 | + Name: gcr.GetName(), |
| 43 | + Namespace: gcr.GetNamespace(), |
| 44 | + }, |
| 45 | + Rules: []rbacapi.PolicyRule{ |
| 46 | + { |
| 47 | + Verbs: []string{"get", "list"}, |
| 48 | + APIGroups: []string{""}, |
| 49 | + Resources: []string{ |
| 50 | + "pods", |
| 51 | + "replicationcontrollers", |
| 52 | + }, |
| 53 | + }, |
| 54 | + { |
| 55 | + Verbs: []string{"list"}, |
| 56 | + APIGroups: []string{""}, |
| 57 | + Resources: []string{ |
| 58 | + "limitranges", |
| 59 | + }, |
| 60 | + }, |
| 61 | + { |
| 62 | + Verbs: []string{"get", "list"}, |
| 63 | + APIGroups: []string{"build.openshift.io", ""}, |
| 64 | + Resources: []string{ |
| 65 | + "buildconfigs", |
| 66 | + "builds", |
| 67 | + }, |
| 68 | + }, |
| 69 | + { |
| 70 | + Verbs: []string{"get", "list"}, |
| 71 | + APIGroups: []string{"apps.openshift.io", ""}, |
| 72 | + Resources: []string{ |
| 73 | + "deploymentconfigs", |
| 74 | + }, |
| 75 | + }, |
| 76 | + { |
| 77 | + Verbs: []string{"get", "list"}, |
| 78 | + APIGroups: []string{"batch"}, |
| 79 | + Resources: []string{ |
| 80 | + "jobs", |
| 81 | + "cronjobs", |
| 82 | + }, |
| 83 | + }, |
| 84 | + { |
| 85 | + Verbs: []string{"get", "list"}, |
| 86 | + APIGroups: []string{"apps"}, |
| 87 | + Resources: []string{ |
| 88 | + "daemonsets", |
| 89 | + "deployments", |
| 90 | + "replicasets", |
| 91 | + "statefulsets", |
| 92 | + }, |
| 93 | + }, |
| 94 | + { |
| 95 | + Verbs: []string{"delete"}, |
| 96 | + APIGroups: []string{"image.openshift.io", ""}, |
| 97 | + Resources: []string{ |
| 98 | + "images", |
| 99 | + }, |
| 100 | + }, |
| 101 | + { |
| 102 | + Verbs: []string{"get", "list", "watch"}, |
| 103 | + APIGroups: []string{"image.openshift.io", ""}, |
| 104 | + Resources: []string{ |
| 105 | + "images", |
| 106 | + "imagestreams", |
| 107 | + }, |
| 108 | + }, |
| 109 | + { |
| 110 | + Verbs: []string{"update"}, |
| 111 | + APIGroups: []string{"image.openshift.io", ""}, |
| 112 | + Resources: []string{ |
| 113 | + "imagestreams/status", |
| 114 | + }, |
| 115 | + }, |
| 116 | + }, |
| 117 | + } |
| 118 | + |
| 119 | + return role, nil |
| 120 | +} |
| 121 | + |
| 122 | +func (gcr *generatorPrunerClusterRole) Get() (runtime.Object, error) { |
| 123 | + return gcr.lister.Get(gcr.GetName()) |
| 124 | +} |
| 125 | + |
| 126 | +func (gcr *generatorPrunerClusterRole) Create() (runtime.Object, error) { |
| 127 | + return commonCreate(gcr, func(obj runtime.Object) (runtime.Object, error) { |
| 128 | + return gcr.client.ClusterRoles().Create( |
| 129 | + context.TODO(), obj.(*rbacapi.ClusterRole), metav1.CreateOptions{}, |
| 130 | + ) |
| 131 | + }) |
| 132 | +} |
| 133 | + |
| 134 | +func (gcr *generatorPrunerClusterRole) Update(o runtime.Object) (runtime.Object, bool, error) { |
| 135 | + return commonUpdate(gcr, o, func(obj runtime.Object) (runtime.Object, error) { |
| 136 | + return gcr.client.ClusterRoles().Update( |
| 137 | + context.TODO(), obj.(*rbacapi.ClusterRole), metav1.UpdateOptions{}, |
| 138 | + ) |
| 139 | + }) |
| 140 | +} |
| 141 | + |
| 142 | +func (gcr *generatorPrunerClusterRole) Delete(opts metav1.DeleteOptions) error { |
| 143 | + return gcr.client.ClusterRoles().Delete( |
| 144 | + context.TODO(), gcr.GetName(), opts, |
| 145 | + ) |
| 146 | +} |
| 147 | + |
| 148 | +func (g *generatorPrunerClusterRole) Owned() bool { |
| 149 | + return true |
| 150 | +} |
0 commit comments