From 8504486c99a2034c3f74280736823aea615c7601 Mon Sep 17 00:00:00 2001 From: Prateek Pandey Date: Fri, 11 Oct 2019 00:58:35 +0530 Subject: [PATCH] refact(cvc): populate version details for csi based volumes (#41) (#42) changes adds new spec versiondetails and set the current and desired versions for cstorvolumeclain resource in case of csi based volume provisioning required during seamless upgrade operations. Refer: openebs/maya/pull/1465 openebs/maya/pull/1466 Signed-off-by: prateekpandey14 --- VERSION | 2 +- .../maya/v1alpha1/cstor_volume_claim.go | 1 + .../maya/v1alpha1/upgrade_details.go | 62 +++++++++++++++++++ .../maya/v1alpha1/zz_generated.deepcopy.go | 35 +++++++++++ pkg/cvc/v1alpha1/build.go | 23 +++++++ pkg/utils/v1alpha1/maya.go | 4 ++ 6 files changed, 126 insertions(+), 1 deletion(-) create mode 100644 pkg/apis/openebs.io/maya/v1alpha1/upgrade_details.go diff --git a/VERSION b/VERSION index 6e8bf73aa..f0bb29e76 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.1.0 +1.3.0 diff --git a/pkg/apis/openebs.io/maya/v1alpha1/cstor_volume_claim.go b/pkg/apis/openebs.io/maya/v1alpha1/cstor_volume_claim.go index 18082a094..0554df183 100644 --- a/pkg/apis/openebs.io/maya/v1alpha1/cstor_volume_claim.go +++ b/pkg/apis/openebs.io/maya/v1alpha1/cstor_volume_claim.go @@ -37,6 +37,7 @@ type CStorVolumeClaim struct { // i.e. NodeId etc. Publish CStorVolumeClaimPublish `json:"publish,omitempty"` + VersionDetails VersionDetails `json:"versionDetails"` // Status represents the current information/status for the cstor volume // claim, populated by the controller. Status CStorVolumeClaimStatus `json:"status"` diff --git a/pkg/apis/openebs.io/maya/v1alpha1/upgrade_details.go b/pkg/apis/openebs.io/maya/v1alpha1/upgrade_details.go new file mode 100644 index 000000000..b2af2ef26 --- /dev/null +++ b/pkg/apis/openebs.io/maya/v1alpha1/upgrade_details.go @@ -0,0 +1,62 @@ +/* +Copyright 2019 The OpenEBS Authors. + +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 v1alpha1 + +import metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + +// VersionDetails provides the details for upgrade +type VersionDetails struct { + // If AutoUpgrade is set to true then the resource is + // upgraded automatically without any manual steps + AutoUpgrade bool `json:"autoUpgrade"` + // Desired is the version that we want to + // upgrade or the control plane version + Desired string `json:"desired"` + // Status gives the status of reconciliation triggered + // when the desired and current version are not same + Status VersionStatus `json:"status"` +} + +// VersionStatus is the status of the reconciliation of versions +type VersionStatus struct { + // DependentsUpgraded gives the details whether all children + // of a resource are upgraded to desired version or not + DependentsUpgraded bool `json:"dependentsUpgraded"` + // Current is the version of resource + Current string `json:"current"` + // State is the state of reconciliation + State VersionState `json:"state"` + // Message is a human readable message if some error occurs + Message string `json:"message,omitempty"` + // Reason is the actual reason for the error state + Reason string `json:"reason,omitempty"` + // LastUpdateTime is the time the status was last updated + LastUpdateTime metav1.Time `json:"lastUpdateTime,omitempty"` +} + +// VersionState is the state of reconciliation +type VersionState string + +const ( + // ReconcileComplete is the state when desired and current version are equal. + ReconcileComplete VersionState = "Reconciled" + // ReconcileInProgress is the state when desired and current version are + // not same and the reconcile functions is retrying to make them same. + ReconcileInProgress VersionState = "ReconcileInProgress" + // ReconcilePending is the state the reconciliation is still not started yet + ReconcilePending VersionState = "ReconcilePending" +) diff --git a/pkg/apis/openebs.io/maya/v1alpha1/zz_generated.deepcopy.go b/pkg/apis/openebs.io/maya/v1alpha1/zz_generated.deepcopy.go index 9c6605074..0ce578118 100644 --- a/pkg/apis/openebs.io/maya/v1alpha1/zz_generated.deepcopy.go +++ b/pkg/apis/openebs.io/maya/v1alpha1/zz_generated.deepcopy.go @@ -139,6 +139,7 @@ func (in *CStorVolumeClaim) DeepCopyInto(out *CStorVolumeClaim) { in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) in.Spec.DeepCopyInto(&out.Spec) out.Publish = in.Publish + in.VersionDetails.DeepCopyInto(&out.VersionDetails) in.Status.DeepCopyInto(&out.Status) return } @@ -412,6 +413,40 @@ func (in *ReplicaStatus) DeepCopy() *ReplicaStatus { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *VersionDetails) DeepCopyInto(out *VersionDetails) { + *out = *in + in.Status.DeepCopyInto(&out.Status) + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new VersionDetails. +func (in *VersionDetails) DeepCopy() *VersionDetails { + if in == nil { + return nil + } + out := new(VersionDetails) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *VersionStatus) DeepCopyInto(out *VersionStatus) { + *out = *in + in.LastUpdateTime.DeepCopyInto(&out.LastUpdateTime) + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new VersionStatus. +func (in *VersionStatus) DeepCopy() *VersionStatus { + if in == nil { + return nil + } + out := new(VersionStatus) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *VolumeCloneSpec) DeepCopyInto(out *VolumeCloneSpec) { *out = *in diff --git a/pkg/cvc/v1alpha1/build.go b/pkg/cvc/v1alpha1/build.go index 921dfd3c6..0f3ba28b0 100644 --- a/pkg/cvc/v1alpha1/build.go +++ b/pkg/cvc/v1alpha1/build.go @@ -346,6 +346,29 @@ func (b *Builder) WithNodeID(nodeID string) *Builder { return b } +// WithNewVersion sets the current and desired version field of +// CStorVolume with provided arguments +func (b *Builder) WithNewVersion(version string) *Builder { + if version == "" { + b.errs = append( + b.errs, + errors.New( + "failed to build cstorvolume object: version can't be empty", + ), + ) + return b + } + b.cvc.object.VersionDetails.Status.Current = version + b.cvc.object.VersionDetails.Desired = version + return b +} + +// WithDependentsUpgraded sets the field to true for new volume +func (b *Builder) WithDependentsUpgraded() *Builder { + b.cvc.object.VersionDetails.Status.DependentsUpgraded = true + return b +} + // Build returns the CStorVolumeClaim API instance func (b *Builder) Build() (*apismaya.CStorVolumeClaim, error) { if len(b.errs) > 0 { diff --git a/pkg/utils/v1alpha1/maya.go b/pkg/utils/v1alpha1/maya.go index 9b32c0781..151401419 100644 --- a/pkg/utils/v1alpha1/maya.go +++ b/pkg/utils/v1alpha1/maya.go @@ -8,7 +8,9 @@ import ( apismaya "github.com/openebs/csi/pkg/apis/openebs.io/maya/v1alpha1" cv "github.com/openebs/csi/pkg/cstor/volume/v1alpha1" cvc "github.com/openebs/csi/pkg/cvc/v1alpha1" + "github.com/openebs/csi/pkg/version" csivol "github.com/openebs/csi/pkg/volume/v1alpha1" + corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/resource" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -68,6 +70,8 @@ func ProvisionVolume( WithFinalizers(finalizers). WithCapacity(sSize). WithReplicaCount(replicaCount). + WithNewVersion(version.Current()). + WithDependentsUpgraded(). WithStatusPhase(apismaya.CStorVolumeClaimPhasePending).Build() if err != nil { return err