Skip to content

Commit

Permalink
ci: fix found linter issues
Browse files Browse the repository at this point in the history
fix all the inter issues for in the repo.

Signed-off-by: Madhu Rajanna <madhupr007@gmail.com>
  • Loading branch information
Madhu-1 authored and mergify[bot] committed Jan 13, 2022
1 parent 19529a7 commit 9c14a8e
Show file tree
Hide file tree
Showing 20 changed files with 237 additions and 125 deletions.
4 changes: 2 additions & 2 deletions api/v1alpha1/groupversion_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ import (
)

var (
// GroupVersion is group version used to register these objects
// GroupVersion is group version used to register these objects.
GroupVersion = schema.GroupVersion{Group: "replication.storage.openshift.io", Version: "v1alpha1"}

// SchemeBuilder is used to add go types to the GroupVersionKind scheme
// SchemeBuilder is used to add go types to the GroupVersionKind scheme.
SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion}

// AddToScheme adds the types in this group-version to the given scheme.
Expand Down
24 changes: 12 additions & 12 deletions api/v1alpha1/volumereplication_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,36 +21,36 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// ReplicationState represents the replication operations to be performed on the volume
// ReplicationState represents the replication operations to be performed on the volume.
// +kubebuilder:validation:Enum=primary;secondary;resync
type ReplicationState string

const (
// Primary ReplicationState enables mirroring and promotes the volume to primary
// Primary ReplicationState enables mirroring and promotes the volume to primary.
Primary ReplicationState = "primary"

// Secondary ReplicationState demotes the volume to secondary and resyncs the volume if out of sync
// Secondary ReplicationState demotes the volume to secondary and resyncs the volume if out of sync.
Secondary ReplicationState = "secondary"

// Resync option resyncs the volume
// Resync option resyncs the volume.
Resync ReplicationState = "resync"
)

// State captures the latest state of the replication operation
// State captures the latest state of the replication operation.
type State string

const (
// PrimaryState represents the Primary replication state
// PrimaryState represents the Primary replication state.
PrimaryState State = "Primary"

// SecondaryState represents the Secondary replication state
// SecondaryState represents the Secondary replication state.
SecondaryState State = "Secondary"

// UnknownState represents the Unknown replication state
// UnknownState represents the Unknown replication state.
UnknownState State = "Unknown"
)

// VolumeReplicationSpec defines the desired state of VolumeReplication
// VolumeReplicationSpec defines the desired state of VolumeReplication.
type VolumeReplicationSpec struct {
// VolumeReplicationClass is the VolumeReplicationClass name for this VolumeReplication resource
// +kubebuilder:validation:Required
Expand All @@ -70,7 +70,7 @@ type VolumeReplicationSpec struct {
ReplicationHandle string `json:"replicationHandle"`
}

// VolumeReplicationStatus defines the observed state of VolumeReplication
// VolumeReplicationStatus defines the observed state of VolumeReplication.
type VolumeReplicationStatus struct {
State State `json:"state,omitempty"`
Message string `json:"message,omitempty"`
Expand All @@ -92,7 +92,7 @@ type VolumeReplicationStatus struct {
// +kubebuilder:printcolumn:JSONPath=".status.state",name=currentState,type=string
// +kubebuilder:resource:shortName=vr

// VolumeReplication is the Schema for the volumereplications API
// VolumeReplication is the Schema for the volumereplications API.
type VolumeReplication struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Expand All @@ -103,7 +103,7 @@ type VolumeReplication struct {

// +kubebuilder:object:root=true

// VolumeReplicationList contains a list of VolumeReplication
// VolumeReplicationList contains a list of VolumeReplication.
type VolumeReplicationList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Expand Down
9 changes: 4 additions & 5 deletions api/v1alpha1/volumereplicationclass_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,15 @@ type VolumeReplicationClassSpec struct {
Parameters map[string]string `json:"parameters,omitempty"`
}

// VolumeReplicationClassStatus defines the observed state of VolumeReplicationClass
type VolumeReplicationClassStatus struct {
}
// VolumeReplicationClassStatus defines the observed state of VolumeReplicationClass.
type VolumeReplicationClassStatus struct{}

// +kubebuilder:object:root=true
// +kubebuilder:subresource:status
// +kubebuilder:resource:scope=Cluster,shortName=vrc
// +kubebuilder:printcolumn:JSONPath=".spec.provisioner",name=provisioner,type=string

// VolumeReplicationClass is the Schema for the volumereplicationclasses API
// VolumeReplicationClass is the Schema for the volumereplicationclasses API.
type VolumeReplicationClass struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Expand All @@ -53,7 +52,7 @@ type VolumeReplicationClass struct {

// +kubebuilder:object:root=true

// VolumeReplicationClassList contains a list of VolumeReplicationClass
// VolumeReplicationClassList contains a list of VolumeReplicationClass.
type VolumeReplicationClassList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Expand Down
1 change: 1 addition & 0 deletions controllers/parameters.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,6 @@ func validatePrefixedParameters(param map[string]string) error {
}
}
}

return nil
}
1 change: 1 addition & 0 deletions controllers/pvc.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ func (r VolumeReplicationReconciler) getPVCDataSource(logger logr.Logger, req ty
if errors.IsNotFound(err) {
logger.Error(err, "PVC not found", "PVC Name", req.Name)
}

return nil, nil, err
}
// Validate PVC in bound state
Expand Down
14 changes: 10 additions & 4 deletions controllers/pvc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ import (

replicationv1alpha1 "github.com/csi-addons/volume-replication-operator/api/v1alpha1"
"github.com/csi-addons/volume-replication-operator/pkg/config"

"github.com/stretchr/testify/assert"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
logf "sigs.k8s.io/controller-runtime/pkg/log"

"sigs.k8s.io/controller-runtime/pkg/client/fake"
logf "sigs.k8s.io/controller-runtime/pkg/log"
)

const (
Expand Down Expand Up @@ -78,6 +78,7 @@ var mockPersistentVolumeClaim = &corev1.PersistentVolumeClaim{
}

func createFakeScheme(t *testing.T) *runtime.Scheme {
t.Helper()
scheme, err := replicationv1alpha1.SchemeBuilder.Build()
if err != nil {
assert.Fail(t, "unable to build scheme")
Expand All @@ -90,10 +91,12 @@ func createFakeScheme(t *testing.T) *runtime.Scheme {
if err != nil {
assert.Fail(t, "failed to add replicationv1alpha1 scheme")
}

return scheme
}

func createFakeVolumeReplicationReconciler(t *testing.T, obj ...runtime.Object) VolumeReplicationReconciler {
t.Helper()
scheme := createFakeScheme(t)
client := fake.NewClientBuilder().WithScheme(scheme).WithRuntimeObjects(obj...).Build()

Expand All @@ -106,6 +109,7 @@ func createFakeVolumeReplicationReconciler(t *testing.T, obj ...runtime.Object)
}

func TestGetVolumeHandle(t *testing.T) {
t.Parallel()
testcases := []struct {
name string
pv *corev1.PersistentVolume
Expand Down Expand Up @@ -156,8 +160,10 @@ func TestGetVolumeHandle(t *testing.T) {
testPVC := &corev1.PersistentVolumeClaim{}
tc.pvc.DeepCopyInto(testPVC)

namespacedName := types.NamespacedName{Name: mockPVCName,
Namespace: volumeReplication.Namespace}
namespacedName := types.NamespacedName{
Name: mockPVCName,
Namespace: volumeReplication.Namespace,
}

reconciler := createFakeVolumeReplicationReconciler(t, testPV, testPVC, volumeReplication)
resultPVC, resultPV, err := reconciler.getPVCDataSource(reconciler.Log, namespacedName)
Expand Down
28 changes: 14 additions & 14 deletions controllers/replication/replication.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ import (
"google.golang.org/grpc/status"
)

// Replication represents the instance of a single replication operation
// Replication represents the instance of a single replication operation.
type Replication struct {
Params CommonRequestParameters
Force bool
}

// ReplicationResponse is the response of a replication operation
type ReplicationResponse struct {
// Response is the response of a replication operation.
type Response struct {
Response interface{}
Error error
}
Expand All @@ -44,29 +44,29 @@ type CommonRequestParameters struct {
Replication client.VolumeReplication
}

func (r *Replication) Enable() *ReplicationResponse {
func (r *Replication) Enable() *Response {
resp, err := r.Params.Replication.EnableVolumeReplication(
r.Params.VolumeID,
r.Params.ReplicationID,
r.Params.Secrets,
r.Params.Parameters,
)

return &ReplicationResponse{Response: resp, Error: err}
return &Response{Response: resp, Error: err}
}

func (r *Replication) Disable() *ReplicationResponse {
func (r *Replication) Disable() *Response {
resp, err := r.Params.Replication.DisableVolumeReplication(
r.Params.VolumeID,
r.Params.ReplicationID,
r.Params.Secrets,
r.Params.Parameters,
)

return &ReplicationResponse{Response: resp, Error: err}
return &Response{Response: resp, Error: err}
}

func (r *Replication) Promote() *ReplicationResponse {
func (r *Replication) Promote() *Response {
resp, err := r.Params.Replication.PromoteVolume(
r.Params.VolumeID,
r.Params.ReplicationID,
Expand All @@ -75,32 +75,32 @@ func (r *Replication) Promote() *ReplicationResponse {
r.Params.Parameters,
)

return &ReplicationResponse{Response: resp, Error: err}
return &Response{Response: resp, Error: err}
}

func (r *Replication) Demote() *ReplicationResponse {
func (r *Replication) Demote() *Response {
resp, err := r.Params.Replication.DemoteVolume(
r.Params.VolumeID,
r.Params.ReplicationID,
r.Params.Secrets,
r.Params.Parameters,
)

return &ReplicationResponse{Response: resp, Error: err}
return &Response{Response: resp, Error: err}
}

func (r *Replication) Resync() *ReplicationResponse {
func (r *Replication) Resync() *Response {
resp, err := r.Params.Replication.ResyncVolume(
r.Params.VolumeID,
r.Params.ReplicationID,
r.Params.Secrets,
r.Params.Parameters,
)

return &ReplicationResponse{Response: resp, Error: err}
return &Response{Response: resp, Error: err}
}

func (r *ReplicationResponse) HasKnownGRPCError(knownErrors []codes.Code) bool {
func (r *Response) HasKnownGRPCError(knownErrors []codes.Code) bool {
if r.Error == nil {
return false
}
Expand Down
9 changes: 6 additions & 3 deletions controllers/replication/replication_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
)

func TestGetMessageFromError(t *testing.T) {
t.Parallel()
tests := []struct {
name string
err error
Expand All @@ -47,9 +48,11 @@ func TestGetMessageFromError(t *testing.T) {
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := GetMessageFromError(tt.err); got != tt.want {
t.Errorf("GetMessageFromError() = %v, want %v", got, tt.want)
newtt := tt
t.Run(newtt.name, func(t *testing.T) {
t.Parallel()
if got := GetMessageFromError(newtt.err); got != newtt.want {
t.Errorf("GetMessageFromError() = %v, want %v", got, newtt.want)
}
})
}
Expand Down

0 comments on commit 9c14a8e

Please sign in to comment.