diff --git a/api/v1alpha1/resourcemanager_types.go b/api/v1alpha1/resourcemanager_types.go index e2736c3..466f700 100644 --- a/api/v1alpha1/resourcemanager_types.go +++ b/api/v1alpha1/resourcemanager_types.go @@ -28,12 +28,12 @@ type ResourceManagerSpec struct { // INSERT ADDITIONAL SPEC FIELDS - desired state of cluster // Important: Run "make" to regenerate code after modifying this file - Active bool `json:"active,omitempty"` - DryRun bool `json:"dry-run,omitempty"` + Disabled bool `json:"active,omitempty"` + DryRun bool `json:"dry-run,omitempty"` // TODO: add validation - Resources string `json:"resources"` - Selector *metav1.LabelSelector `json:"selector"` + ResourceKind string `json:"resourceKind"` + Selector *metav1.LabelSelector `json:"selector"` // TODO: add validation + enum Action string `json:"action"` diff --git a/config/crd/bases/resource-management.tikalk.com_resourcemanagers.yaml b/config/crd/bases/resource-management.tikalk.com_resourcemanagers.yaml index 6793c54..0e26085 100644 --- a/config/crd/bases/resource-management.tikalk.com_resourcemanagers.yaml +++ b/config/crd/bases/resource-management.tikalk.com_resourcemanagers.yaml @@ -1,9 +1,10 @@ + --- apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: annotations: - controller-gen.kubebuilder.io/version: v0.9.2 + controller-gen.kubebuilder.io/version: v0.7.0 creationTimestamp: null name: resourcemanagers.resource-management.tikalk.com spec: @@ -54,7 +55,7 @@ spec: type: array dry-run: type: boolean - resources: + resourceKind: description: 'TODO: add validation' type: string selector: @@ -104,11 +105,10 @@ spec: are ANDed. type: object type: object - x-kubernetes-map-type: atomic required: - action - condition - - resources + - resourceKind - selector type: object status: @@ -119,3 +119,9 @@ spec: storage: true subresources: status: {} +status: + acceptedNames: + kind: "" + plural: "" + conditions: [] + storedVersions: [] diff --git a/config/crd/bases/resource-managment.tikalk.com_resourcemanagers.yaml b/config/crd/bases/resource-managment.tikalk.com_resourcemanagers.yaml deleted file mode 100644 index 4064d90..0000000 --- a/config/crd/bases/resource-managment.tikalk.com_resourcemanagers.yaml +++ /dev/null @@ -1,127 +0,0 @@ - ---- -apiVersion: apiextensions.k8s.io/v1 -kind: CustomResourceDefinition -metadata: - annotations: - controller-gen.kubebuilder.io/version: v0.7.0 - creationTimestamp: null - name: resourcemanagers.resource-management.tikalk.com -spec: - group: resource-management.tikalk.com - names: - kind: ResourceManager - listKind: ResourceManagerList - plural: resourcemanagers - singular: resourcemanager - scope: Namespaced - versions: - - name: v1alpha1 - schema: - openAPIV3Schema: - description: ResourceManager is the Schema for the resourcemanagers API - properties: - apiVersion: - description: 'APIVersion defines the versioned schema of this representation - of an object. Servers should convert recognized schemas to the latest - internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources' - type: string - kind: - description: 'Kind is a string value representing the REST resource this - object represents. Servers may infer this from the endpoint the client - submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' - type: string - metadata: - type: object - spec: - description: ResourceManagerSpec defines the desired state of ResourceManager - properties: - action: - description: 'TODO: add validation + enum' - type: string - active: - type: boolean - condition: - items: - properties: - after: - type: string - type: - type: string - required: - - after - - type - type: object - type: array - dry-run: - type: boolean - resources: - description: 'TODO: add validation' - type: string - selector: - description: A label selector is a label query over a set of resources. - The result of matchLabels and matchExpressions are ANDed. An empty - label selector matches all objects. A null label selector matches - no objects. - properties: - matchExpressions: - description: matchExpressions is a list of label selector requirements. - The requirements are ANDed. - items: - description: A label selector requirement is a selector that - contains values, a key, and an operator that relates the key - and values. - properties: - key: - description: key is the label key that the selector applies - to. - type: string - operator: - description: operator represents a key's relationship to - a set of values. Valid operators are In, NotIn, Exists - and DoesNotExist. - type: string - values: - description: values is an array of string values. If the - operator is In or NotIn, the values array must be non-empty. - If the operator is Exists or DoesNotExist, the values - array must be empty. This array is replaced during a strategic - merge patch. - items: - type: string - type: array - required: - - key - - operator - type: object - type: array - matchLabels: - additionalProperties: - type: string - description: matchLabels is a map of {key,value} pairs. A single - {key,value} in the matchLabels map is equivalent to an element - of matchExpressions, whose key field is "key", the operator - is "In", and the values array contains only "value". The requirements - are ANDed. - type: object - type: object - required: - - action - - condition - - resources - - selector - type: object - status: - description: ResourceManagerStatus defines the observed state of ResourceManager - type: object - type: object - served: true - storage: true - subresources: - status: {} -status: - acceptedNames: - kind: "" - plural: "" - conditions: [] - storedVersions: [] diff --git a/config/rbac/role.yaml b/config/rbac/role.yaml index 9cc9c18..27127d7 100644 --- a/config/rbac/role.yaml +++ b/config/rbac/role.yaml @@ -1,3 +1,4 @@ + --- apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRole diff --git a/config/samples/resource-managment_v1alpha1_resourcemanager.yaml b/config/samples/resource-managment_v1alpha1_resourcemanager.yaml index b0abcf4..cdbc6e7 100644 --- a/config/samples/resource-managment_v1alpha1_resourcemanager.yaml +++ b/config/samples/resource-managment_v1alpha1_resourcemanager.yaml @@ -3,9 +3,9 @@ kind: ResourceManager metadata: name: resource-manager-sample spec: - active: true + disabled: false dry-run: false - resources: "namespace" + resourceKind: "namespace" selector: matchLabels: name: managed-namespace1 diff --git a/controllers/resourcemanager_controller.go b/controllers/resourcemanager_controller.go index 8b832f7..c2accef 100644 --- a/controllers/resourcemanager_controller.go +++ b/controllers/resourcemanager_controller.go @@ -100,7 +100,7 @@ func (r *ResourceManagerReconciler) Reconcile(ctx context.Context, req ctrl.Requ " action: %s \n"+ " condition: %s \n"+ " type: %s \n", - h.Spec.Resources, + h.Spec.ResourceKind, h.Spec.Selector.MatchLabels, h.Spec.Action, h.Spec.Condition[0].After, @@ -114,7 +114,7 @@ func (r *ResourceManagerReconciler) Reconcile(ctx context.Context, req ctrl.Requ delete(collection, h.Name) } - switch h.Spec.Resources { + switch h.Spec.ResourceKind { case "namespace": // add the function and its stop-channel to collection collection[h.Name] = FHandler{ diff --git a/controllers/resourcemanager_controller_test.go b/controllers/resourcemanager_controller_test.go index a71973e..b0840bb 100644 --- a/controllers/resourcemanager_controller_test.go +++ b/controllers/resourcemanager_controller_test.go @@ -24,9 +24,9 @@ var _ = Context("Inside of a ResourceManager", func() { Namespace: "default", }, Spec: resourcemanagmentv1alpha1.ResourceManagerSpec{ - Active: true, - DryRun: false, - Resources: "namespace", + Disabled: false, + DryRun: false, + ResourceKind: "Namespace", Selector: &metav1.LabelSelector{ MatchLabels: map[string]string{ "name": "managed-namespace", @@ -65,7 +65,7 @@ var _ = Context("Inside of a ResourceManager", func() { }, } err = k8sClient.Create(ctx, myNamespaceObj) - Expect(err).NotTo(HaveOccurred(), "failed to create test 'namespace' resource") + Expect(err).NotTo(HaveOccurred(), "failed to create test 'Namespace' resource") // validate creation nsObj, _ := getResourceByName(ctx, myNamespaceObj.Name)