diff --git a/operators/constellation-node-operator/PROJECT b/operators/constellation-node-operator/PROJECT index 8e01baef5..b0a09966c 100644 --- a/operators/constellation-node-operator/PROJECT +++ b/operators/constellation-node-operator/PROJECT @@ -15,4 +15,12 @@ resources: kind: NodeImage path: github.com/edgelesssys/constellation/operators/constellation-node-operator/api/v1alpha1 version: v1alpha1 +- api: + crdVersion: v1 + controller: true + domain: edgeless.systems + group: update + kind: AutoscalingStrategy + path: github.com/edgelesssys/constellation/operators/constellation-node-operator/api/v1alpha1 + version: v1alpha1 version: "3" diff --git a/operators/constellation-node-operator/api/v1alpha1/autoscalingstrategy_types.go b/operators/constellation-node-operator/api/v1alpha1/autoscalingstrategy_types.go new file mode 100644 index 000000000..236f1e0c0 --- /dev/null +++ b/operators/constellation-node-operator/api/v1alpha1/autoscalingstrategy_types.go @@ -0,0 +1,50 @@ + +package v1alpha1 + +import ( + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" +) + +// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN! +// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized. + +// AutoscalingStrategySpec defines the desired state of AutoscalingStrategy +type AutoscalingStrategySpec struct { + // INSERT ADDITIONAL SPEC FIELDS - desired state of cluster + // Important: Run "make" to regenerate code after modifying this file + + // Foo is an example field of AutoscalingStrategy. Edit autoscalingstrategy_types.go to remove/update + Foo string `json:"foo,omitempty"` +} + +// AutoscalingStrategyStatus defines the observed state of AutoscalingStrategy +type AutoscalingStrategyStatus struct { + // INSERT ADDITIONAL STATUS FIELD - define observed state of cluster + // Important: Run "make" to regenerate code after modifying this file +} + +//+kubebuilder:object:root=true +//+kubebuilder:subresource:status +//+kubebuilder:resource:scope=Cluster + +// AutoscalingStrategy is the Schema for the autoscalingstrategies API +type AutoscalingStrategy struct { + metav1.TypeMeta `json:",inline"` + metav1.ObjectMeta `json:"metadata,omitempty"` + + Spec AutoscalingStrategySpec `json:"spec,omitempty"` + Status AutoscalingStrategyStatus `json:"status,omitempty"` +} + +//+kubebuilder:object:root=true + +// AutoscalingStrategyList contains a list of AutoscalingStrategy +type AutoscalingStrategyList struct { + metav1.TypeMeta `json:",inline"` + metav1.ListMeta `json:"metadata,omitempty"` + Items []AutoscalingStrategy `json:"items"` +} + +func init() { + SchemeBuilder.Register(&AutoscalingStrategy{}, &AutoscalingStrategyList{}) +} diff --git a/operators/constellation-node-operator/api/v1alpha1/zz_generated.deepcopy.go b/operators/constellation-node-operator/api/v1alpha1/zz_generated.deepcopy.go index 7b024b1c9..fafdd1524 100644 --- a/operators/constellation-node-operator/api/v1alpha1/zz_generated.deepcopy.go +++ b/operators/constellation-node-operator/api/v1alpha1/zz_generated.deepcopy.go @@ -10,6 +10,95 @@ import ( runtime "k8s.io/apimachinery/pkg/runtime" ) +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *AutoscalingStrategy) DeepCopyInto(out *AutoscalingStrategy) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) + out.Spec = in.Spec + out.Status = in.Status +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new AutoscalingStrategy. +func (in *AutoscalingStrategy) DeepCopy() *AutoscalingStrategy { + if in == nil { + return nil + } + out := new(AutoscalingStrategy) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *AutoscalingStrategy) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *AutoscalingStrategyList) DeepCopyInto(out *AutoscalingStrategyList) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ListMeta.DeepCopyInto(&out.ListMeta) + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]AutoscalingStrategy, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new AutoscalingStrategyList. +func (in *AutoscalingStrategyList) DeepCopy() *AutoscalingStrategyList { + if in == nil { + return nil + } + out := new(AutoscalingStrategyList) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *AutoscalingStrategyList) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *AutoscalingStrategySpec) DeepCopyInto(out *AutoscalingStrategySpec) { + *out = *in +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new AutoscalingStrategySpec. +func (in *AutoscalingStrategySpec) DeepCopy() *AutoscalingStrategySpec { + if in == nil { + return nil + } + out := new(AutoscalingStrategySpec) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *AutoscalingStrategyStatus) DeepCopyInto(out *AutoscalingStrategyStatus) { + *out = *in +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new AutoscalingStrategyStatus. +func (in *AutoscalingStrategyStatus) DeepCopy() *AutoscalingStrategyStatus { + if in == nil { + return nil + } + out := new(AutoscalingStrategyStatus) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *NodeImage) DeepCopyInto(out *NodeImage) { *out = *in diff --git a/operators/constellation-node-operator/config/crd/bases/update.edgeless.systems_autoscalingstrategies.yaml b/operators/constellation-node-operator/config/crd/bases/update.edgeless.systems_autoscalingstrategies.yaml new file mode 100644 index 000000000..44bbdb9e9 --- /dev/null +++ b/operators/constellation-node-operator/config/crd/bases/update.edgeless.systems_autoscalingstrategies.yaml @@ -0,0 +1,51 @@ +--- +apiVersion: apiextensions.k8s.io/v1 +kind: CustomResourceDefinition +metadata: + annotations: + controller-gen.kubebuilder.io/version: v0.9.0 + creationTimestamp: null + name: autoscalingstrategies.update.edgeless.systems +spec: + group: update.edgeless.systems + names: + kind: AutoscalingStrategy + listKind: AutoscalingStrategyList + plural: autoscalingstrategies + singular: autoscalingstrategy + scope: Cluster + versions: + - name: v1alpha1 + schema: + openAPIV3Schema: + description: AutoscalingStrategy is the Schema for the autoscalingstrategies + 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: AutoscalingStrategySpec defines the desired state of AutoscalingStrategy + properties: + foo: + description: Foo is an example field of AutoscalingStrategy. Edit + autoscalingstrategy_types.go to remove/update + type: string + type: object + status: + description: AutoscalingStrategyStatus defines the observed state of AutoscalingStrategy + type: object + type: object + served: true + storage: true + subresources: + status: {} diff --git a/operators/constellation-node-operator/config/crd/kustomization.yaml b/operators/constellation-node-operator/config/crd/kustomization.yaml index 911b6fd58..725b65a4a 100644 --- a/operators/constellation-node-operator/config/crd/kustomization.yaml +++ b/operators/constellation-node-operator/config/crd/kustomization.yaml @@ -3,17 +3,20 @@ # It should be run by config/default resources: - bases/update.edgeless.systems_nodeimages.yaml +- bases/update.edgeless.systems_autoscalingstrategies.yaml #+kubebuilder:scaffold:crdkustomizeresource patchesStrategicMerge: # [WEBHOOK] To enable webhook, uncomment all the sections with [WEBHOOK] prefix. # patches here are for enabling the conversion webhook for each CRD #- patches/webhook_in_nodeimages.yaml +#- patches/webhook_in_autoscalingstrategies.yaml #+kubebuilder:scaffold:crdkustomizewebhookpatch # [CERTMANAGER] To enable cert-manager, uncomment all the sections with [CERTMANAGER] prefix. # patches here are for enabling the CA injection for each CRD #- patches/cainjection_in_nodeimages.yaml +#- patches/cainjection_in_autoscalingstrategies.yaml #+kubebuilder:scaffold:crdkustomizecainjectionpatch # the following config is for teaching kustomize how to do kustomization for CRDs. diff --git a/operators/constellation-node-operator/config/crd/patches/cainjection_in_autoscalingstrategies.yaml b/operators/constellation-node-operator/config/crd/patches/cainjection_in_autoscalingstrategies.yaml new file mode 100644 index 000000000..5310bc710 --- /dev/null +++ b/operators/constellation-node-operator/config/crd/patches/cainjection_in_autoscalingstrategies.yaml @@ -0,0 +1,7 @@ +# The following patch adds a directive for certmanager to inject CA into the CRD +apiVersion: apiextensions.k8s.io/v1 +kind: CustomResourceDefinition +metadata: + annotations: + cert-manager.io/inject-ca-from: $(CERTIFICATE_NAMESPACE)/$(CERTIFICATE_NAME) + name: autoscalingstrategies.update.edgeless.systems diff --git a/operators/constellation-node-operator/config/crd/patches/webhook_in_autoscalingstrategies.yaml b/operators/constellation-node-operator/config/crd/patches/webhook_in_autoscalingstrategies.yaml new file mode 100644 index 000000000..14cbc2601 --- /dev/null +++ b/operators/constellation-node-operator/config/crd/patches/webhook_in_autoscalingstrategies.yaml @@ -0,0 +1,16 @@ +# The following patch enables a conversion webhook for the CRD +apiVersion: apiextensions.k8s.io/v1 +kind: CustomResourceDefinition +metadata: + name: autoscalingstrategies.update.edgeless.systems +spec: + conversion: + strategy: Webhook + webhook: + clientConfig: + service: + namespace: system + name: webhook-service + path: /convert + conversionReviewVersions: + - v1 diff --git a/operators/constellation-node-operator/config/rbac/autoscalingstrategy_editor_role.yaml b/operators/constellation-node-operator/config/rbac/autoscalingstrategy_editor_role.yaml new file mode 100644 index 000000000..f61a3d203 --- /dev/null +++ b/operators/constellation-node-operator/config/rbac/autoscalingstrategy_editor_role.yaml @@ -0,0 +1,24 @@ +# permissions for end users to edit autoscalingstrategies. +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRole +metadata: + name: autoscalingstrategy-editor-role +rules: +- apiGroups: + - update.edgeless.systems + resources: + - autoscalingstrategies + verbs: + - create + - delete + - get + - list + - patch + - update + - watch +- apiGroups: + - update.edgeless.systems + resources: + - autoscalingstrategies/status + verbs: + - get diff --git a/operators/constellation-node-operator/config/rbac/autoscalingstrategy_viewer_role.yaml b/operators/constellation-node-operator/config/rbac/autoscalingstrategy_viewer_role.yaml new file mode 100644 index 000000000..9b333e70a --- /dev/null +++ b/operators/constellation-node-operator/config/rbac/autoscalingstrategy_viewer_role.yaml @@ -0,0 +1,20 @@ +# permissions for end users to view autoscalingstrategies. +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRole +metadata: + name: autoscalingstrategy-viewer-role +rules: +- apiGroups: + - update.edgeless.systems + resources: + - autoscalingstrategies + verbs: + - get + - list + - watch +- apiGroups: + - update.edgeless.systems + resources: + - autoscalingstrategies/status + verbs: + - get diff --git a/operators/constellation-node-operator/config/rbac/role.yaml b/operators/constellation-node-operator/config/rbac/role.yaml index 61936230b..c9046e989 100644 --- a/operators/constellation-node-operator/config/rbac/role.yaml +++ b/operators/constellation-node-operator/config/rbac/role.yaml @@ -5,6 +5,32 @@ metadata: creationTimestamp: null name: manager-role rules: +- apiGroups: + - update.edgeless.systems + resources: + - autoscalingstrategies + verbs: + - create + - delete + - get + - list + - patch + - update + - watch +- apiGroups: + - update.edgeless.systems + resources: + - autoscalingstrategies/finalizers + verbs: + - update +- apiGroups: + - update.edgeless.systems + resources: + - autoscalingstrategies/status + verbs: + - get + - patch + - update - apiGroups: - update.edgeless.systems resources: diff --git a/operators/constellation-node-operator/config/samples/kustomization.yaml b/operators/constellation-node-operator/config/samples/kustomization.yaml index 9fb855b33..936355159 100644 --- a/operators/constellation-node-operator/config/samples/kustomization.yaml +++ b/operators/constellation-node-operator/config/samples/kustomization.yaml @@ -1,4 +1,5 @@ ## Append samples you want in your CSV to this file as resources ## resources: - update_v1alpha1_nodeimage.yaml +- update_v1alpha1_autoscalingstrategy.yaml #+kubebuilder:scaffold:manifestskustomizesamples diff --git a/operators/constellation-node-operator/config/samples/update_v1alpha1_autoscalingstrategy.yaml b/operators/constellation-node-operator/config/samples/update_v1alpha1_autoscalingstrategy.yaml new file mode 100644 index 000000000..11eeffd62 --- /dev/null +++ b/operators/constellation-node-operator/config/samples/update_v1alpha1_autoscalingstrategy.yaml @@ -0,0 +1,6 @@ +apiVersion: update.edgeless.systems/v1alpha1 +kind: AutoscalingStrategy +metadata: + name: autoscalingstrategy-sample +spec: + # TODO(user): Add fields here diff --git a/operators/constellation-node-operator/controllers/autoscalingstrategy_controller.go b/operators/constellation-node-operator/controllers/autoscalingstrategy_controller.go new file mode 100644 index 000000000..19dbbbbfb --- /dev/null +++ b/operators/constellation-node-operator/controllers/autoscalingstrategy_controller.go @@ -0,0 +1,47 @@ + +package controllers + +import ( + "context" + + "k8s.io/apimachinery/pkg/runtime" + ctrl "sigs.k8s.io/controller-runtime" + "sigs.k8s.io/controller-runtime/pkg/client" + "sigs.k8s.io/controller-runtime/pkg/log" + + updatev1alpha1 "github.com/edgelesssys/constellation/operators/constellation-node-operator/api/v1alpha1" +) + +// AutoscalingStrategyReconciler reconciles a AutoscalingStrategy object +type AutoscalingStrategyReconciler struct { + client.Client + Scheme *runtime.Scheme +} + +//+kubebuilder:rbac:groups=update.edgeless.systems,resources=autoscalingstrategies,verbs=get;list;watch;create;update;patch;delete +//+kubebuilder:rbac:groups=update.edgeless.systems,resources=autoscalingstrategies/status,verbs=get;update;patch +//+kubebuilder:rbac:groups=update.edgeless.systems,resources=autoscalingstrategies/finalizers,verbs=update + +// Reconcile is part of the main kubernetes reconciliation loop which aims to +// move the current state of the cluster closer to the desired state. +// TODO(user): Modify the Reconcile function to compare the state specified by +// the AutoscalingStrategy object against the actual cluster state, and then +// perform operations to make the cluster state reflect the state specified by +// the user. +// +// For more details, check Reconcile and its Result here: +// - https://pkg.go.dev/sigs.k8s.io/controller-runtime@v0.11.2/pkg/reconcile +func (r *AutoscalingStrategyReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) { + _ = log.FromContext(ctx) + + // TODO(user): your logic here + + return ctrl.Result{}, nil +} + +// SetupWithManager sets up the controller with the Manager. +func (r *AutoscalingStrategyReconciler) SetupWithManager(mgr ctrl.Manager) error { + return ctrl.NewControllerManagedBy(mgr). + For(&updatev1alpha1.AutoscalingStrategy{}). + Complete(r) +} diff --git a/operators/constellation-node-operator/main.go b/operators/constellation-node-operator/main.go index 5243dee02..5d6c71ea6 100644 --- a/operators/constellation-node-operator/main.go +++ b/operators/constellation-node-operator/main.go @@ -70,6 +70,13 @@ func main() { setupLog.Error(err, "unable to create controller", "controller", "NodeImage") os.Exit(1) } + if err = (&controllers.AutoscalingStrategyReconciler{ + Client: mgr.GetClient(), + Scheme: mgr.GetScheme(), + }).SetupWithManager(mgr); err != nil { + setupLog.Error(err, "unable to create controller", "controller", "AutoscalingStrategy") + os.Exit(1) + } //+kubebuilder:scaffold:builder if err := mgr.AddHealthzCheck("healthz", healthz.Ping); err != nil {