diff --git a/PROJECT b/PROJECT index ffa200e12..afbb95eb2 100644 --- a/PROJECT +++ b/PROJECT @@ -1,3 +1,7 @@ +# Code generated by tool. DO NOT EDIT. +# This file is used to track the info used to scaffold your project +# and allow the plugins properly work. +# More info: https://book.kubebuilder.io/reference/project-config.html domain: openstack.org layout: - go.kubebuilder.io/v3 @@ -29,4 +33,13 @@ resources: kind: OpenStackClient path: github.com/openstack-k8s-operators/openstack-operator/apis/client/v1beta1 version: v1beta1 +- api: + crdVersion: v1 + namespaced: true + controller: true + domain: openstack.org + group: core + kind: OpenStackVersion + path: github.com/openstack-k8s-operators/openstack-operator/apis/core/v1beta1 + version: v1beta1 version: "3" diff --git a/apis/core/v1beta1/openstackversion_types.go b/apis/core/v1beta1/openstackversion_types.go new file mode 100644 index 000000000..9c0b53af3 --- /dev/null +++ b/apis/core/v1beta1/openstackversion_types.go @@ -0,0 +1,64 @@ +/* +Copyright 2022. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package v1beta1 + +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. + +// OpenStackVersionSpec defines the desired state of OpenStackVersion +type OpenStackVersionSpec 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 OpenStackVersion. Edit openstackversion_types.go to remove/update + Foo string `json:"foo,omitempty"` +} + +// OpenStackVersionStatus defines the observed state of OpenStackVersion +type OpenStackVersionStatus 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 + +// OpenStackVersion is the Schema for the openstackversions API +type OpenStackVersion struct { + metav1.TypeMeta `json:",inline"` + metav1.ObjectMeta `json:"metadata,omitempty"` + + Spec OpenStackVersionSpec `json:"spec,omitempty"` + Status OpenStackVersionStatus `json:"status,omitempty"` +} + +//+kubebuilder:object:root=true + +// OpenStackVersionList contains a list of OpenStackVersion +type OpenStackVersionList struct { + metav1.TypeMeta `json:",inline"` + metav1.ListMeta `json:"metadata,omitempty"` + Items []OpenStackVersion `json:"items"` +} + +func init() { + SchemeBuilder.Register(&OpenStackVersion{}, &OpenStackVersionList{}) +} diff --git a/apis/core/v1beta1/zz_generated.deepcopy.go b/apis/core/v1beta1/zz_generated.deepcopy.go index 5a973122c..6cc8dedb8 100644 --- a/apis/core/v1beta1/zz_generated.deepcopy.go +++ b/apis/core/v1beta1/zz_generated.deepcopy.go @@ -578,6 +578,95 @@ func (in *OpenStackExtraVolMounts) DeepCopy() *OpenStackExtraVolMounts { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *OpenStackVersion) DeepCopyInto(out *OpenStackVersion) { + *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 OpenStackVersion. +func (in *OpenStackVersion) DeepCopy() *OpenStackVersion { + if in == nil { + return nil + } + out := new(OpenStackVersion) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *OpenStackVersion) 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 *OpenStackVersionList) DeepCopyInto(out *OpenStackVersionList) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ListMeta.DeepCopyInto(&out.ListMeta) + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]OpenStackVersion, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new OpenStackVersionList. +func (in *OpenStackVersionList) DeepCopy() *OpenStackVersionList { + if in == nil { + return nil + } + out := new(OpenStackVersionList) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *OpenStackVersionList) 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 *OpenStackVersionSpec) DeepCopyInto(out *OpenStackVersionSpec) { + *out = *in +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new OpenStackVersionSpec. +func (in *OpenStackVersionSpec) DeepCopy() *OpenStackVersionSpec { + if in == nil { + return nil + } + out := new(OpenStackVersionSpec) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *OpenStackVersionStatus) DeepCopyInto(out *OpenStackVersionStatus) { + *out = *in +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new OpenStackVersionStatus. +func (in *OpenStackVersionStatus) DeepCopy() *OpenStackVersionStatus { + if in == nil { + return nil + } + out := new(OpenStackVersionStatus) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *Override) DeepCopyInto(out *Override) { *out = *in diff --git a/config/crd/kustomization.yaml b/config/crd/kustomization.yaml index a70647ec8..cface3851 100644 --- a/config/crd/kustomization.yaml +++ b/config/crd/kustomization.yaml @@ -3,6 +3,7 @@ # It should be run by config/default resources: - bases/core.openstack.org_openstackcontrolplanes.yaml +- bases/core.openstack.org_openstackversions.yaml - bases/client.openstack.org_openstackclients.yaml #+kubebuilder:scaffold:crdkustomizeresource @@ -11,12 +12,14 @@ patchesStrategicMerge: # patches here are for enabling the conversion webhook for each CRD #- patches/webhook_in_core_openstackcontrolplanes.yaml #- patches/webhook_in_openstackclients.yaml +#- patches/webhook_in_openstackversions.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_core_openstackcontrolplanes.yaml #- patches/cainjection_in_openstackclients.yaml +#- patches/cainjection_in_openstackversions.yaml #+kubebuilder:scaffold:crdkustomizecainjectionpatch # the following config is for teaching kustomize how to do kustomization for CRDs. diff --git a/config/crd/patches/cainjection_in_core_openstackversions.yaml b/config/crd/patches/cainjection_in_core_openstackversions.yaml new file mode 100644 index 000000000..03d16fa38 --- /dev/null +++ b/config/crd/patches/cainjection_in_core_openstackversions.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: openstackversions.core.openstack.org diff --git a/config/crd/patches/webhook_in_core_openstackversions.yaml b/config/crd/patches/webhook_in_core_openstackversions.yaml new file mode 100644 index 000000000..3970fb91f --- /dev/null +++ b/config/crd/patches/webhook_in_core_openstackversions.yaml @@ -0,0 +1,16 @@ +# The following patch enables a conversion webhook for the CRD +apiVersion: apiextensions.k8s.io/v1 +kind: CustomResourceDefinition +metadata: + name: openstackversions.core.openstack.org +spec: + conversion: + strategy: Webhook + webhook: + clientConfig: + service: + namespace: system + name: webhook-service + path: /convert + conversionReviewVersions: + - v1 diff --git a/config/rbac/core_openstackversion_editor_role.yaml b/config/rbac/core_openstackversion_editor_role.yaml new file mode 100644 index 000000000..e274cb878 --- /dev/null +++ b/config/rbac/core_openstackversion_editor_role.yaml @@ -0,0 +1,31 @@ +# permissions for end users to edit openstackversions. +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRole +metadata: + labels: + app.kubernetes.io/name: clusterrole + app.kubernetes.io/instance: openstackversion-editor-role + app.kubernetes.io/component: rbac + app.kubernetes.io/created-by: openstack-operator + app.kubernetes.io/part-of: openstack-operator + app.kubernetes.io/managed-by: kustomize + name: openstackversion-editor-role +rules: +- apiGroups: + - core.openstack.org + resources: + - openstackversions + verbs: + - create + - delete + - get + - list + - patch + - update + - watch +- apiGroups: + - core.openstack.org + resources: + - openstackversions/status + verbs: + - get diff --git a/config/rbac/core_openstackversion_viewer_role.yaml b/config/rbac/core_openstackversion_viewer_role.yaml new file mode 100644 index 000000000..25c4bcc90 --- /dev/null +++ b/config/rbac/core_openstackversion_viewer_role.yaml @@ -0,0 +1,27 @@ +# permissions for end users to view openstackversions. +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRole +metadata: + labels: + app.kubernetes.io/name: clusterrole + app.kubernetes.io/instance: openstackversion-viewer-role + app.kubernetes.io/component: rbac + app.kubernetes.io/created-by: openstack-operator + app.kubernetes.io/part-of: openstack-operator + app.kubernetes.io/managed-by: kustomize + name: openstackversion-viewer-role +rules: +- apiGroups: + - core.openstack.org + resources: + - openstackversions + verbs: + - get + - list + - watch +- apiGroups: + - core.openstack.org + resources: + - openstackversions/status + verbs: + - get diff --git a/config/samples/core_v1beta1_openstackcontrolplane_lightweight.yaml b/config/samples/core_v1beta1_openstackcontrolplane_lightweight.yaml new file mode 100644 index 000000000..2abc19560 --- /dev/null +++ b/config/samples/core_v1beta1_openstackcontrolplane_lightweight.yaml @@ -0,0 +1,195 @@ +apiVersion: core.openstack.org/v1beta1 +kind: OpenStackControlPlane +metadata: + name: openstack-basic +spec: + secret: osp-secret + storageClass: local-storage + #tls: + # endpoint: + # internal: + # enabled: false + # public: + # enabled: true + keystone: + template: + databaseInstance: openstack + secret: osp-secret + mariadb: + templates: + openstack: + storageRequest: 500M + openstack-cell1: + storageRequest: 500M + galera: + enabled: false + templates: + openstack: + storageClass: local-storage + storageRequest: 500M + secret: osp-secret + replicas: 1 + openstack-cell1: + storageClass: local-storage + storageRequest: 500M + secret: osp-secret + replicas: 1 + rabbitmq: + templates: + rabbitmq: + replicas: 1 + #resources: + # requests: + # cpu: 500m + # memory: 1Gi + # limits: + # cpu: 800m + # memory: 1Gi + rabbitmq-cell1: + replicas: 1 + memcached: + templates: + memcached: + replicas: 1 + barbican: + enabled: false + template: + databaseInstance: openstack + secret: osp-secret + barbicanAPI: + replicas: 1 + barbicanWorker: + replicas: 1 + barbicanKeystoneListener: + replicas: 1 + placement: + template: + databaseInstance: openstack + secret: osp-secret + glance: + template: + secret: osp-secret + databaseInstance: openstack + storageClass: "" + storageRequest: 10G + glanceAPI: + type: single + replicas: 1 + cinder: + template: + databaseInstance: openstack + secret: osp-secret + cinderAPI: + replicas: 1 + cinderScheduler: + replicas: 1 + cinderBackup: + replicas: 0 # backend needs to be configured + cinderVolumes: + volume1: + replicas: 0 # backend needs to be configured + manila: + enabled: false + template: + manilaAPI: + replicas: 1 + manilaScheduler: + replicas: 1 + manilaShares: + share1: + replicas: 1 + ovn: + template: + ovnDBCluster: + ovndbcluster-nb: + replicas: 1 + dbType: NB + storageRequest: 10G + ovndbcluster-sb: + replicas: 1 + dbType: SB + storageRequest: 10G + ovnNorthd: + replicas: 1 + ovnController: + external-ids: + system-id: "random" + ovn-bridge: "br-int" + ovn-encap-type: "geneve" + neutron: + template: + databaseInstance: openstack + secret: osp-secret + horizon: + enabled: false + template: + replicas: 1 + secret: osp-secret + nova: + template: + secret: osp-secret + heat: + enabled: false + template: + databaseInstance: openstack + heatAPI: + replicas: 1 + heatEngine: + replicas: 1 + secret: osp-secret + ironic: + enabled: false + template: + databaseInstance: openstack + ironicAPI: + replicas: 1 + ironicConductors: + - replicas: 1 + storageRequest: 10G + ironicInspector: + replicas: 1 + ironicNeutronAgent: + replicas: 1 + secret: osp-secret + ceilometer: + enabled: false + template: + passwordSelector: + service: CeilometerPassword + secret: osp-secret + serviceUser: ceilometer + swift: + enabled: false + template: + swiftRing: + ringReplicas: 1 + swiftStorage: + replicas: 1 + swiftProxy: + replicas: 1 + octavia: + enabled: false + template: + databaseInstance: openstack + octaviaAPI: + replicas: 1 + secret: osp-secret + redis: + enabled: false + designate: + enabled: false + template: + databaseInstance: openstack + secret: osp-secret + designateAPI: + replicas: 1 + designateCentral: + replicas: 0 # backend needs to be configured + designateWorker: + replicas: 0 # backend needs to be configured + designateProducer: + replicas: 0 # backend needs to be configured + designateMdns: + replicas: 0 # backend needs to be configured + designateBackendbind9: + replicas: 0 # backend needs to be configured diff --git a/config/samples/core_v1beta1_openstackversion.yaml b/config/samples/core_v1beta1_openstackversion.yaml new file mode 100644 index 000000000..0649671d8 --- /dev/null +++ b/config/samples/core_v1beta1_openstackversion.yaml @@ -0,0 +1,12 @@ +apiVersion: core.openstack.org/v1beta1 +kind: OpenStackVersion +metadata: + labels: + app.kubernetes.io/name: openstackversion + app.kubernetes.io/instance: openstackversion-sample + app.kubernetes.io/part-of: openstack-operator + app.kubernetes.io/managed-by: kustomize + app.kubernetes.io/created-by: openstack-operator + name: openstackversion-sample +spec: + # TODO(user): Add fields here diff --git a/config/samples/kustomization.yaml b/config/samples/kustomization.yaml index 4f0f8c764..2b198bae2 100644 --- a/config/samples/kustomization.yaml +++ b/config/samples/kustomization.yaml @@ -4,4 +4,5 @@ resources: - core_v1beta1_openstackcontrolplane_collapsed_cell.yaml - core_v1beta1_openstackcontrolplane_network_isolation.yaml - client_v1beta1_openstackclient.yaml +- core_v1beta1_openstackversion.yaml #+kubebuilder:scaffold:manifestskustomizesamples diff --git a/controllers/core/openstackversion_controller.go b/controllers/core/openstackversion_controller.go new file mode 100644 index 000000000..6e30284db --- /dev/null +++ b/controllers/core/openstackversion_controller.go @@ -0,0 +1,62 @@ +/* +Copyright 2022. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package core + +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" + + corev1beta1 "github.com/openstack-k8s-operators/openstack-operator/apis/core/v1beta1" +) + +// OpenStackVersionReconciler reconciles a OpenStackVersion object +type OpenStackVersionReconciler struct { + client.Client + Scheme *runtime.Scheme +} + +//+kubebuilder:rbac:groups=core.openstack.org,resources=openstackversions,verbs=get;list;watch;create;update;patch;delete +//+kubebuilder:rbac:groups=core.openstack.org,resources=openstackversions/status,verbs=get;update;patch +//+kubebuilder:rbac:groups=core.openstack.org,resources=openstackversions/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 OpenStackVersion 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.14.1/pkg/reconcile +func (r *OpenStackVersionReconciler) 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 *OpenStackVersionReconciler) SetupWithManager(mgr ctrl.Manager) error { + return ctrl.NewControllerManagedBy(mgr). + For(&corev1beta1.OpenStackVersion{}). + Complete(r) +} diff --git a/main.go b/main.go index f96568981..566d19822 100644 --- a/main.go +++ b/main.go @@ -69,8 +69,10 @@ import ( metricsserver "sigs.k8s.io/controller-runtime/pkg/metrics/server" routev1 "github.com/openshift/api/route/v1" + clientv1 "github.com/openstack-k8s-operators/openstack-operator/apis/client/v1beta1" corev1 "github.com/openstack-k8s-operators/openstack-operator/apis/core/v1beta1" + corev1beta1 "github.com/openstack-k8s-operators/openstack-operator/apis/core/v1beta1" clientcontrollers "github.com/openstack-k8s-operators/openstack-operator/controllers/client" corecontrollers "github.com/openstack-k8s-operators/openstack-operator/controllers/core" "github.com/openstack-k8s-operators/openstack-operator/pkg/openstack" @@ -113,6 +115,7 @@ func init() { utilruntime.Must(routev1.AddToScheme(scheme)) utilruntime.Must(certmgrv1.AddToScheme(scheme)) utilruntime.Must(barbicanv1.AddToScheme(scheme)) + utilruntime.Must(corev1beta1.AddToScheme(scheme)) //+kubebuilder:scaffold:scheme } @@ -230,6 +233,13 @@ func main() { checker = mgr.GetWebhookServer().StartedChecker() } + if err = (&corecontrollers.OpenStackVersionReconciler{ + Client: mgr.GetClient(), + Scheme: mgr.GetScheme(), + }).SetupWithManager(mgr); err != nil { + setupLog.Error(err, "unable to create controller", "controller", "OpenStackVersion") + os.Exit(1) + } //+kubebuilder:scaffold:builder if err := mgr.AddHealthzCheck("healthz", checker); err != nil {