diff --git a/PROJECT b/PROJECT index 4f3863cc80..b97ad022e0 100644 --- a/PROJECT +++ b/PROJECT @@ -51,4 +51,13 @@ resources: kind: StorageRequest path: github.com/red-hat-storage/ocs-operator/api/v4/v1alpha1 version: v1alpha1 +- api: + crdVersion: v1 + namespaced: true + controller: true + domain: openshift.io + group: ocs + kind: StorageClusterPeer + path: github.com/red-hat-storage/ocs-operator/api/v4/v1 + version: v1 version: "3" diff --git a/api/v1/groupversion_info.go b/api/v1/groupversion_info.go index af76991754..0bd23f33b4 100644 --- a/api/v1/groupversion_info.go +++ b/api/v1/groupversion_info.go @@ -44,6 +44,7 @@ func addKnownTypes(scheme *runtime.Scheme) error { &OCSInitialization{}, &OCSInitializationList{}, &StorageCluster{}, &StorageClusterList{}, &StorageProfile{}, &StorageProfileList{}, + &StorageClusterPeer{}, &StorageClusterPeerList{}, ) metav1.AddToGroupVersion(scheme, GroupVersion) return nil diff --git a/api/v1/storageclusterpeer_types.go b/api/v1/storageclusterpeer_types.go new file mode 100644 index 0000000000..44164cc379 --- /dev/null +++ b/api/v1/storageclusterpeer_types.go @@ -0,0 +1,73 @@ +/* +Copyright 2020 Red Hat OpenShift Container Storage. + +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 v1 + +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. + +type StorageClusterPeerState string + +const ( + StorageClusterPeerFinalizer = "storageclusterpeer.ocs.openshift.io" +) + +// StorageClusterPeerSpec defines the desired state of StorageClusterPeer +type StorageClusterPeerSpec struct { + + // APIServerEndpoint is the URI of the ocs api server + APIServerEndpoint string `json:"APIServerEndpoint"` + + // OnboardingTicket holds an identity information required for provider to onboard. + OnboardingTicket string `json:"onboardingTicket"` +} + +// StorageClusterPeerStatus defines the observed state of StorageClusterPeer +type StorageClusterPeerStatus struct { + + // Phase describes the Phase of StorageClusterPeer + // This is used by OLM UI to provide status information to the user + Phase StorageClusterPeerState `json:"phase,omitempty"` + + // PeerID will hold the ID of representation of this resource in the attached provider cluster + PeerID string `json:"id,omitempty"` +} + +//+kubebuilder:object:root=true +//+kubebuilder:subresource:status + +// StorageClusterPeer is the Schema for the storageclusterpeers API +type StorageClusterPeer struct { + metav1.TypeMeta `json:",inline"` + metav1.ObjectMeta `json:"metadata,omitempty"` + + // +kubebuilder:validation:Required + Spec StorageClusterPeerSpec `json:"spec,omitempty"` + Status StorageClusterPeerStatus `json:"status,omitempty"` +} + +//+kubebuilder:object:root=true + +// StorageClusterPeerList contains a list of StorageClusterPeer +type StorageClusterPeerList struct { + metav1.TypeMeta `json:",inline"` + metav1.ListMeta `json:"metadata,omitempty"` + Items []StorageClusterPeer `json:"items"` +} diff --git a/config/crd/kustomization.yaml b/config/crd/kustomization.yaml index 23ef658b01..1a6367a70b 100644 --- a/config/crd/kustomization.yaml +++ b/config/crd/kustomization.yaml @@ -7,6 +7,7 @@ resources: - bases/ocs.openshift.io_storageconsumers.yaml - bases/ocs.openshift.io_storagerequests.yaml - bases/ocs.openshift.io_storageprofiles.yaml +- bases/ocs.openshift.io_storageclusterpeers.yaml # +kubebuilder:scaffold:crdkustomizeresource # patchesStrategicMerge: @@ -17,6 +18,7 @@ resources: #- patches/webhook_in_storageconsumers.yaml #- patches/webhook_in_storagerequests.yaml #- patches/webhook_in_storageprofiles.yaml +#- patches/webhook_in_storageclusterpeers.yaml # +kubebuilder:scaffold:crdkustomizewebhookpatch # [CERTMANAGER] To enable webhook, uncomment all the sections with [CERTMANAGER] prefix. @@ -26,6 +28,7 @@ resources: #- patches/cainjection_in_storageconsumers.yaml #- patches/cainjection_in_storagerequests.yaml #- patches/cainjection_in_storageprofiles.yaml +#- patches/cainjection_in_storageclusterpeers.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_storageclusterpeers.yaml b/config/crd/patches/cainjection_in_storageclusterpeers.yaml new file mode 100644 index 0000000000..49fa87e731 --- /dev/null +++ b/config/crd/patches/cainjection_in_storageclusterpeers.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: storageclusterpeers.ocs.openshift.io diff --git a/config/crd/patches/webhook_in_storageclusterpeers.yaml b/config/crd/patches/webhook_in_storageclusterpeers.yaml new file mode 100644 index 0000000000..23f3724556 --- /dev/null +++ b/config/crd/patches/webhook_in_storageclusterpeers.yaml @@ -0,0 +1,16 @@ +# The following patch enables a conversion webhook for the CRD +apiVersion: apiextensions.k8s.io/v1 +kind: CustomResourceDefinition +metadata: + name: storageclusterpeers.ocs.openshift.io +spec: + conversion: + strategy: Webhook + webhook: + clientConfig: + service: + namespace: system + name: webhook-service + path: /convert + conversionReviewVersions: + - v1 diff --git a/config/rbac/storageclusterpeer_editor_role.yaml b/config/rbac/storageclusterpeer_editor_role.yaml new file mode 100644 index 0000000000..5a7bbfbc51 --- /dev/null +++ b/config/rbac/storageclusterpeer_editor_role.yaml @@ -0,0 +1,31 @@ +# permissions for end users to edit storageclusterpeers. +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRole +metadata: + labels: + app.kubernetes.io/name: clusterrole + app.kubernetes.io/instance: storageclusterpeer-editor-role + app.kubernetes.io/component: rbac + app.kubernetes.io/created-by: ocs-operator + app.kubernetes.io/part-of: ocs-operator + app.kubernetes.io/managed-by: kustomize + name: storageclusterpeer-editor-role +rules: +- apiGroups: + - ocs.openshift.io + resources: + - storageclusterpeers + verbs: + - create + - delete + - get + - list + - patch + - update + - watch +- apiGroups: + - ocs.openshift.io + resources: + - storageclusterpeers/status + verbs: + - get diff --git a/config/rbac/storageclusterpeer_viewer_role.yaml b/config/rbac/storageclusterpeer_viewer_role.yaml new file mode 100644 index 0000000000..e616824491 --- /dev/null +++ b/config/rbac/storageclusterpeer_viewer_role.yaml @@ -0,0 +1,27 @@ +# permissions for end users to view storageclusterpeers. +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRole +metadata: + labels: + app.kubernetes.io/name: clusterrole + app.kubernetes.io/instance: storageclusterpeer-viewer-role + app.kubernetes.io/component: rbac + app.kubernetes.io/created-by: ocs-operator + app.kubernetes.io/part-of: ocs-operator + app.kubernetes.io/managed-by: kustomize + name: storageclusterpeer-viewer-role +rules: +- apiGroups: + - ocs.openshift.io + resources: + - storageclusterpeers + verbs: + - get + - list + - watch +- apiGroups: + - ocs.openshift.io + resources: + - storageclusterpeers/status + verbs: + - get diff --git a/config/samples/kustomization.yaml b/config/samples/kustomization.yaml index bff9db7c1e..556d0eaba0 100644 --- a/config/samples/kustomization.yaml +++ b/config/samples/kustomization.yaml @@ -4,4 +4,5 @@ resources: - ocs_v1_storagecluster.yaml - ocs_v1alpha1_storageconsumer.yaml - ocs_v1_storageprofile.yaml +- ocs_v1_storageclusterpeer.yaml # +kubebuilder:scaffold:manifestskustomizesamples diff --git a/config/samples/ocs_v1_storageclusterpeer.yaml b/config/samples/ocs_v1_storageclusterpeer.yaml new file mode 100644 index 0000000000..b6f1e71dfc --- /dev/null +++ b/config/samples/ocs_v1_storageclusterpeer.yaml @@ -0,0 +1,8 @@ +apiVersion: ocs.openshift.io/v1 +kind: StorageClusterPeer +metadata: + name: storageclusterpeer-sample + namespace: openshift-storage +spec: + APIServerEndpoint: 10.0.0.0:31659 + onboardingTicket: onboarding-token diff --git a/controllers/storageclusterpeer/storageclusterpeer_controller.go b/controllers/storageclusterpeer/storageclusterpeer_controller.go new file mode 100644 index 0000000000..04f8e7f5ec --- /dev/null +++ b/controllers/storageclusterpeer/storageclusterpeer_controller.go @@ -0,0 +1,62 @@ +/* +Copyright 2020 Red Hat OpenShift Container Storage. + +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 storageclusterpeer + +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" + + v1 "github.com/red-hat-storage/ocs-operator/api/v4/v1" +) + +// StorageClusterPeerReconciler reconciles a StorageClusterPeer object +type StorageClusterPeerReconciler struct { + client.Client + Scheme *runtime.Scheme +} + +//+kubebuilder:rbac:groups=ocs.openshift.io,resources=storageclusterpeers,verbs=get;list;watch;create;update;patch;delete +//+kubebuilder:rbac:groups=ocs.openshift.io,resources=storageclusterpeers/status,verbs=get;update;patch +//+kubebuilder:rbac:groups=ocs.openshift.io,resources=storageclusterpeers/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 StorageClusterPeer 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.13.0/pkg/reconcile +func (r *StorageClusterPeerReconciler) 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 *StorageClusterPeerReconciler) SetupWithManager(mgr ctrl.Manager) error { + return ctrl.NewControllerManagedBy(mgr). + For(&v1.StorageClusterPeer{}). + Complete(r) +} diff --git a/main.go b/main.go index 9f12b87513..4782f7417d 100644 --- a/main.go +++ b/main.go @@ -38,12 +38,6 @@ import ( ocsclientv1a1 "github.com/red-hat-storage/ocs-client-operator/api/v1alpha1" ocsv1 "github.com/red-hat-storage/ocs-operator/api/v4/v1" ocsv1alpha1 "github.com/red-hat-storage/ocs-operator/api/v4/v1alpha1" - "github.com/red-hat-storage/ocs-operator/v4/controllers/ocsinitialization" - "github.com/red-hat-storage/ocs-operator/v4/controllers/platform" - "github.com/red-hat-storage/ocs-operator/v4/controllers/storagecluster" - controllers "github.com/red-hat-storage/ocs-operator/v4/controllers/storageconsumer" - "github.com/red-hat-storage/ocs-operator/v4/controllers/storagerequest" - "github.com/red-hat-storage/ocs-operator/v4/controllers/util" cephv1 "github.com/rook/rook/pkg/apis/ceph.rook.io/v1" batchv1 "k8s.io/api/batch/v1" corev1 "k8s.io/api/core/v1" @@ -62,6 +56,14 @@ import ( apiclient "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/log/zap" metrics "sigs.k8s.io/controller-runtime/pkg/metrics/server" + + "github.com/red-hat-storage/ocs-operator/v4/controllers/ocsinitialization" + "github.com/red-hat-storage/ocs-operator/v4/controllers/platform" + "github.com/red-hat-storage/ocs-operator/v4/controllers/storagecluster" + "github.com/red-hat-storage/ocs-operator/v4/controllers/storageclusterpeer" + controllers "github.com/red-hat-storage/ocs-operator/v4/controllers/storageconsumer" + "github.com/red-hat-storage/ocs-operator/v4/controllers/storagerequest" + "github.com/red-hat-storage/ocs-operator/v4/controllers/util" // +kubebuilder:scaffold:imports ) @@ -205,6 +207,13 @@ func main() { setupLog.Error(err, "unable to create controller", "controller", "StorageRequest") os.Exit(1) } + if err = (&storageclusterpeer.StorageClusterPeerReconciler{ + Client: mgr.GetClient(), + Scheme: mgr.GetScheme(), + }).SetupWithManager(mgr); err != nil { + setupLog.Error(err, "unable to create controller", "controller", "StorageClusterPeer") + os.Exit(1) + } // +kubebuilder:scaffold:builder // Create OCSInitialization CR if it's not present