Skip to content

Commit

Permalink
Add new CR and controller for storageClusterPeer
Browse files Browse the repository at this point in the history
ran the command:
operator-sdk create api --group ocs --version v1
--kind StorageClusterPeer --resource --controller

Signed-off-by: Rewant Soni <resoni@redhat.com>
  • Loading branch information
rewantsoni committed Jul 22, 2024
1 parent 92a5407 commit ede4515
Show file tree
Hide file tree
Showing 12 changed files with 253 additions and 6 deletions.
9 changes: 9 additions & 0 deletions PROJECT
Original file line number Diff line number Diff line change
Expand Up @@ -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"
1 change: 1 addition & 0 deletions api/v1/groupversion_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ func addKnownTypes(scheme *runtime.Scheme) error {
&OCSInitialization{}, &OCSInitializationList{},
&StorageCluster{}, &StorageClusterList{},
&StorageProfile{}, &StorageProfileList{},
&StorageClusterPeer{}, &StorageClusterPeerList{},
)
metav1.AddToGroupVersion(scheme, GroupVersion)
return nil
Expand Down
73 changes: 73 additions & 0 deletions api/v1/storageclusterpeer_types.go
Original file line number Diff line number Diff line change
@@ -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"`
}
3 changes: 3 additions & 0 deletions config/crd/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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.
Expand All @@ -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.
Expand Down
7 changes: 7 additions & 0 deletions config/crd/patches/cainjection_in_storageclusterpeers.yaml
Original file line number Diff line number Diff line change
@@ -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
16 changes: 16 additions & 0 deletions config/crd/patches/webhook_in_storageclusterpeers.yaml
Original file line number Diff line number Diff line change
@@ -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
31 changes: 31 additions & 0 deletions config/rbac/storageclusterpeer_editor_role.yaml
Original file line number Diff line number Diff line change
@@ -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
27 changes: 27 additions & 0 deletions config/rbac/storageclusterpeer_viewer_role.yaml
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions config/samples/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ resources:
- ocs_v1_storagecluster.yaml
- ocs_v1alpha1_storageconsumer.yaml
- ocs_v1_storageprofile.yaml
- ocs_v1_storageclusterpeer.yaml
# +kubebuilder:scaffold:manifestskustomizesamples
8 changes: 8 additions & 0 deletions config/samples/ocs_v1_storageclusterpeer.yaml
Original file line number Diff line number Diff line change
@@ -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
62 changes: 62 additions & 0 deletions controllers/storageclusterpeer/storageclusterpeer_controller.go
Original file line number Diff line number Diff line change
@@ -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)
}
21 changes: 15 additions & 6 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
)

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit ede4515

Please sign in to comment.