Skip to content

Commit

Permalink
refact(cvc): populate version details for csi based volumes (#41) (#42)
Browse files Browse the repository at this point in the history
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-archive/maya/pull/1465
       openebs-archive/maya/pull/1466

Signed-off-by: prateekpandey14 <[email protected]>
  • Loading branch information
prateekpandey14 authored and vishnuitta committed Oct 10, 2019
1 parent 4727200 commit 8504486
Show file tree
Hide file tree
Showing 6 changed files with 126 additions and 1 deletion.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.1.0
1.3.0
1 change: 1 addition & 0 deletions pkg/apis/openebs.io/maya/v1alpha1/cstor_volume_claim.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
62 changes: 62 additions & 0 deletions pkg/apis/openebs.io/maya/v1alpha1/upgrade_details.go
Original file line number Diff line number Diff line change
@@ -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"
)
35 changes: 35 additions & 0 deletions pkg/apis/openebs.io/maya/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 23 additions & 0 deletions pkg/cvc/v1alpha1/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 4 additions & 0 deletions pkg/utils/v1alpha1/maya.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 8504486

Please sign in to comment.