Skip to content

Commit

Permalink
Adding 'version' field to 'StorageCluster'
Browse files Browse the repository at this point in the history
This version string could be picked by the openshift-console UI

Signed-off-by: Arun Kumar Mohan <[email protected]>
  • Loading branch information
aruniiird committed Feb 20, 2020
1 parent 1642412 commit b7bfdb2
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 3 deletions.
7 changes: 7 additions & 0 deletions deploy/crds/ocs_v1_storagecluster_crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ spec:
- JSONPath: .metadata.creationTimestamp
name: Created At
type: string
- JSONPath: .spec.version
description: Storage Cluster Version
name: Version
type: string
group: ocs.openshift.io
names:
kind: StorageCluster
Expand Down Expand Up @@ -107,6 +111,9 @@ spec:
- dataPVCTemplate
type: object
type: array
version:
description: Version specifies the version of StorageCluster
type: string
type: object
status:
properties:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ metadata:
capabilities: Full Lifecycle
categories: Storage
containerImage: quay.io/ocs-dev/ocs-operator:4.3.0
createdAt: "2020-02-19 13:10:11"
createdAt: "2020-02-20 15:11:04"
description: Red Hat OpenShift Container Storage provides hyperconverged storage
for applications within an OpenShift cluster.
operators.operatorframework.io/internal-objects: '["cephclusters.ceph.rook.io",
Expand Down
7 changes: 7 additions & 0 deletions deploy/olm-catalog/ocs-operator/4.3.0/storagecluster.crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ spec:
- JSONPath: .metadata.creationTimestamp
name: Created At
type: string
- JSONPath: .spec.version
description: Storage Cluster Version
name: Version
type: string
group: ocs.openshift.io
names:
kind: StorageCluster
Expand Down Expand Up @@ -108,6 +112,9 @@ spec:
- dataPVCTemplate
type: object
type: array
version:
description: Version specifies the version of StorageCluster
type: string
type: object
status:
properties:
Expand Down
2 changes: 1 addition & 1 deletion hack/latest-csv-checksum.md5
Original file line number Diff line number Diff line change
@@ -1 +1 @@
d2139fc1632e9f9e2fa8568f9e9e3372
04b1409ecf9dc126396dcc1fa4353af4
3 changes: 3 additions & 0 deletions pkg/apis/ocs/v1/storagecluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ type StorageClusterSpec struct {
StorageDeviceSets []StorageDeviceSet `json:"storageDeviceSets,omitempty"`
MonPVCTemplate *corev1.PersistentVolumeClaim `json:"monPVCTemplate,omitempty"`
MonDataDirHostPath string `json:"monDataDirHostPath,omitempty"`
// Version specifies the version of StorageCluster
Version string `json:"version,omitempty"`
}

// StorageDeviceSet defines a set of storage devices.
Expand Down Expand Up @@ -129,6 +131,7 @@ const (
// +kubebuilder:printcolumn:name="Age",type=date,JSONPath=.metadata.creationTimestamp
// +kubebuilder:printcolumn:name="Phase",type=string,JSONPath=.status.phase,description="Current Phase"
// +kubebuilder:printcolumn:name="Created At",type=string,JSONPath=.metadata.creationTimestamp
// +kubebuilder:printcolumn:name="Version",type=string,JSONPath=.spec.version,description="Storage Cluster Version"
type StorageCluster struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Expand Down
27 changes: 27 additions & 0 deletions pkg/controller/storagecluster/reconcile.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"strconv"
"strings"

"github.com/blang/semver"
"github.com/go-logr/logr"
"github.com/operator-framework/operator-sdk/pkg/ready"
corev1 "k8s.io/api/core/v1"
Expand All @@ -27,6 +28,7 @@ import (
ocsv1 "github.com/openshift/ocs-operator/pkg/apis/ocs/v1"
"github.com/openshift/ocs-operator/pkg/controller/defaults"
statusutil "github.com/openshift/ocs-operator/pkg/controller/util"
"github.com/openshift/ocs-operator/version"
cephv1 "github.com/rook/rook/pkg/apis/ceph.rook.io/v1"
rook "github.com/rook/rook/pkg/apis/rook.io/v1alpha2"
)
Expand Down Expand Up @@ -75,6 +77,31 @@ func (r *ReconcileStorageCluster) Reconcile(request reconcile.Request) (reconcil
return reconcile.Result{}, err
}

if instance.Spec.Version == "" {
instance.Spec.Version = version.Version
} else if instance.Spec.Version != version.Version { // check anything else only if the versions mis-match
storClustSemV1, err := semver.Make(instance.Spec.Version)
if err != nil {
reqLogger.Error(err, "Error while parsing Storage Cluster version")
return reconcile.Result{}, err
}
ocsSemV1, err := semver.Make(version.Version)
if err != nil {
reqLogger.Error(err, "Error while parsing OCS Operator version")
return reconcile.Result{}, err
}
// if the storage cluster version is higher than the invoking OCS Operator's version,
// return error
if storClustSemV1.GT(ocsSemV1) {
err = fmt.Errorf("Storage cluster version (%s) is higher than the OCS Operator version (%s)",
instance.Spec.Version, version.Version)
reqLogger.Error(err, "Incompatible Storage cluster version")
return reconcile.Result{}, err
}
// if the storage cluster version is less than the OCS Operator version,
// just update.
instance.Spec.Version = version.Version
}
// Check for active StorageCluster only if Create request is made
// and ignore it if there's another active StorageCluster
// If Update request is made and StorageCluster is PhaseIgnored, no need to
Expand Down
2 changes: 1 addition & 1 deletion version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ package version

var (
// Version of the operator
Version = "0.0.1"
Version = "4.3.0"
)

0 comments on commit b7bfdb2

Please sign in to comment.