Skip to content

Commit

Permalink
feat: Move supported resources from hard-coded to ConfigMap
Browse files Browse the repository at this point in the history
  • Loading branch information
dvirgilad authored and maromcohen committed Aug 28, 2024
1 parent e343ccd commit 3c2e120
Show file tree
Hide file tree
Showing 25 changed files with 142 additions and 7 deletions.
1 change: 1 addition & 0 deletions .uuid
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
f3706efb-ea7d-4e78-9c9a-d5412e55edb5
1 change: 1 addition & 0 deletions api/.uuid
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
01377e02-87b5-4dfc-b9bf-45ad94210c5c
1 change: 1 addition & 0 deletions api/v1/.uuid
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
486815d6-9bf7-43d8-9941-ebbe8df4ebca
1 change: 1 addition & 0 deletions chart/.uuid
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
24694e4e-6f3a-4950-a7b7-07ee167740da
1 change: 1 addition & 0 deletions chart/templates/.uuid
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
47fb98b5-0962-49f4-809c-8373643e362a
1 change: 1 addition & 0 deletions cmd/.uuid
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
af428c8f-4e9f-42e3-a1de-5be141c95bc4
1 change: 1 addition & 0 deletions config/.uuid
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
770b17c3-4aee-4c68-bdfe-86833661fdab
11 changes: 11 additions & 0 deletions config/configMap.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: quota-resources-config-map
namespace: sns-system
data:
storage: "50Gi"
cpu: '50'
memory: "50Gi"
pods: '50'
gpu: '0'
6 changes: 6 additions & 0 deletions config/crd/bases/dana.hns.io_subnamespaces.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,13 @@ spec:
items:
type: string
type: array
x-kubernetes-list-type: atomic
required:
- operator
- scopeName
type: object
type: array
x-kubernetes-list-type: atomic
type: object
x-kubernetes-map-type: atomic
scopes:
Expand All @@ -113,6 +115,7 @@ spec:
match each object tracked by a quota
type: string
type: array
x-kubernetes-list-type: atomic
type: object
type: object
status:
Expand Down Expand Up @@ -174,11 +177,13 @@ spec:
items:
type: string
type: array
x-kubernetes-list-type: atomic
required:
- operator
- scopeName
type: object
type: array
x-kubernetes-list-type: atomic
type: object
x-kubernetes-map-type: atomic
scopes:
Expand All @@ -190,6 +195,7 @@ spec:
must match each object tracked by a quota
type: string
type: array
x-kubernetes-list-type: atomic
type: object
type: object
type: array
Expand Down
3 changes: 3 additions & 0 deletions config/crd/bases/dana.hns.io_updatequotas.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,13 @@ spec:
items:
type: string
type: array
x-kubernetes-list-type: atomic
required:
- operator
- scopeName
type: object
type: array
x-kubernetes-list-type: atomic
type: object
x-kubernetes-map-type: atomic
scopes:
Expand All @@ -107,6 +109,7 @@ spec:
match each object tracked by a quota
type: string
type: array
x-kubernetes-list-type: atomic
type: object
sourcens:
description: SourceNamespace is name of the Subnamespace from which
Expand Down
26 changes: 19 additions & 7 deletions config/manager/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,24 @@
resources:
- manager.yaml
- manager.yaml

apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization

images:
- name: controller
newName: controller
newTag: latest
- name: controller
newName: controller
newTag: latest

configMapGenerator:
- literals:
- PERMITTED_GROUPS='test'
name: permitted-groups-cm
- literals:
- PERMITTED_GROUPS='test'
name: permitted-groups-cm

- name: quota-resources-config-map
namespace: sns-system
literals:
- storage="50Gi"
- cpu="50"
- memory="50Gi"
- pods="50"
- gpu="0"
8 changes: 8 additions & 0 deletions config/rbac/configmap_role.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: configmap-role
rules:
- apiGroups: [""]
resources: ["configmaps"]
verbs: ["get", "list", "watch"]
12 changes: 12 additions & 0 deletions config/rbac/configmap_role_binding.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: configmap-role-binding
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: configmap-role
subjects:
- kind: ServiceAccount
name: sns-controller-manager
namespace: sns-system
12 changes: 12 additions & 0 deletions config/rbac/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,18 @@ rules:
- users
verbs:
- impersonate
- apiGroups:
- ""
resources:
- configmaps
verbs:
- create
- delete
- get
- list
- patch
- update
- watch
- apiGroups:
- ""
resources:
Expand Down
1 change: 1 addition & 0 deletions docs/.uuid
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0cbeae48-24b6-4ea1-b7ec-a67ed1ce4356
1 change: 1 addition & 0 deletions hack/.uuid
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2a1947b0-da97-4283-a783-0b8e501a6276
1 change: 1 addition & 0 deletions internal/.uuid
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
7478c10d-0a98-40db-9fa4-4d2c638e8403
1 change: 1 addition & 0 deletions internal/subnamespace/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ type snsPhaseFunc func(*objectcontext.ObjectContext, *objectcontext.ObjectContex
// +kubebuilder:rbac:groups="",resources=resourcequotas,verbs=get;list;watch;create;update;patch;delete
// +kubebuilder:rbac:groups="quota.openshift.io",resources=clusterresourcequotas,verbs=get;list;watch;create;update;patch;delete
// +kubebuilder:rbac:groups="",resources=limitranges,verbs=get;list;watch;create;update;patch;delete
// +kubebuilder:rbac:groups=core,resources=configmaps,verbs=get;list;watch;create;update;patch;delete

// SetupWithManager sets up the controller by specifying the following: controller is managing the reconciliation
// of subnamespace objects and is watching for changes to the SNSEvents channel and enqueues requests for the
Expand Down
1 change: 1 addition & 0 deletions internal/updatequota/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ type UpdateQuotaReconciler struct {
// +kubebuilder:rbac:groups=dana.hns.io,resources=updatequota/status,verbs=get;update;patch
// +kubebuilder:rbac:groups=user.openshift.io,resources=groups,verbs=get;list;watch
// +kubebuilder:rbac:groups="",resources=users,verbs=impersonate
// +kubebuilder:rbac:groups=core,resources=configmaps,verbs=get;list;watch;create;update;patch;delete

func (r *UpdateQuotaReconciler) SetupWithManager(mgr ctrl.Manager) error {
return ctrl.NewControllerManagedBy(mgr).
Expand Down
7 changes: 7 additions & 0 deletions mh.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
apiVersion: dana.hns.io/v1
kind: MigrationHierarchy
metadata:
name: 'braziltojapan'
spec:
currentns: 'brazil'
tons: 'japan'
10 changes: 10 additions & 0 deletions ns.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
kind: Namespace
apiVersion: v1
metadata:
name: brazil
labels:
dana.hns.io/role: leaf
dana.hns.io/subnamespace: 'true'
kubernetes.io/metadata.name: brazil
dana.hns.io/parent: root-test
dana.hns.io/resourcepool: 'false'
13 changes: 13 additions & 0 deletions rootns.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
kind: Namespace
apiVersion: v1
metadata:
name: rootns
labels:
dana.hns.io/subnamespace: 'true'
annotations:
dana.hns.io/role: root
openshift.io/display-name: rootns
dana.hns.io/display-name: rootns
dana.hns.io/crq-selector-0: rootns
dana.hns.io/depth: '0'
dana.hns.io/rq-depth: '1'
15 changes: 15 additions & 0 deletions sns.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
apiVersion: dana.hns.io/v1
kind: Subnamespace
metadata:
name: 'brazil'
namespace: 'coffee'
labels:
dana.hns.io/resourcepool: 'false'
spec:
resourcequota:
hard:
cpu: '1'
memory: 1Gi
pods: 2
basic.storageclass.storage.k8s.io/requests.storage: 0
requests.nvidia.com/gpu: '0'
1 change: 1 addition & 0 deletions test/.uuid
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
131ae9c2-868d-4961-b347-15bab54837d3
13 changes: 13 additions & 0 deletions uq.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
apiVersion: dana.hns.io/v1
kind: Updatequota
metadata:
annotations:
dana.hns.io/description: 'Moving resources for this great new project'
namespace: brazil
name: 'braziltojapan'
spec:
destns: japan
resourcequota:
hard:
pods: '1'
sourcens: brazil

0 comments on commit 3c2e120

Please sign in to comment.