Skip to content

Commit

Permalink
Merge pull request #189 from red-hat-storage/sync_us--main
Browse files Browse the repository at this point in the history
Syncing latest changes from upstream main for kubernetes-csi-addons
  • Loading branch information
openshift-merge-bot[bot] authored Sep 2, 2024
2 parents cce0f35 + 32e811c commit 8dfe24b
Show file tree
Hide file tree
Showing 15 changed files with 3,275 additions and 11 deletions.
7 changes: 0 additions & 7 deletions config/default/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
# Adds namespace to all resources.
namespace: csi-addons-system

# Value of this field is prepended to the
# names of all resources, e.g. a deployment named
# "wordpress" becomes "alices-wordpress".
# Note that it should also match with the prefix (text before '-') of the namespace
# field above.
namePrefix: csi-addons-

# Labels to add to all resources and selectors.
#labels:
#- includeSelectors: true
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.22.0

require (
github.com/container-storage-interface/spec v1.10.0
github.com/csi-addons/spec v0.2.1-0.20240718113938-dc98b454ba65
github.com/csi-addons/spec v0.2.1-0.20240730084235-3958a5b17d24
github.com/go-logr/logr v1.4.2
github.com/kubernetes-csi/csi-lib-utils v0.18.1
github.com/onsi/ginkgo/v2 v2.20.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XL
github.com/container-storage-interface/spec v1.10.0 h1:YkzWPV39x+ZMTa6Ax2czJLLwpryrQ+dPesB34mrRMXA=
github.com/container-storage-interface/spec v1.10.0/go.mod h1:DtUvaQszPml1YJfIK7c00mlv6/g4wNMLanLgiUbKFRI=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/csi-addons/spec v0.2.1-0.20240718113938-dc98b454ba65 h1:i9JGGQTEmRQXSpQQPR96+DV4D4o+V1+gjAWf+bpxQxk=
github.com/csi-addons/spec v0.2.1-0.20240718113938-dc98b454ba65/go.mod h1:Mwq4iLiUV4s+K1bszcWU6aMsR5KPsbIYzzszJ6+56vI=
github.com/csi-addons/spec v0.2.1-0.20240730084235-3958a5b17d24 h1:tJETaYbnnzlCSaqDXQzbszYyuAtG/sFzm6DargeVzJA=
github.com/csi-addons/spec v0.2.1-0.20240730084235-3958a5b17d24/go.mod h1:Mwq4iLiUV4s+K1bszcWU6aMsR5KPsbIYzzszJ6+56vI=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
Expand Down
51 changes: 51 additions & 0 deletions internal/client/fake/volumegroup-client.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
Copyright 2024 The Kubernetes-CSI-Addons 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 fake

import "github.com/csi-addons/kubernetes-csi-addons/internal/proto"

// VolumeGroupClient to fake grouping operations.
type VolumeGroupClient struct {
// CreateVolumeGroupMock mocks CreateVolumeGroup RPC call.
CreateVolumeGroupMock func(volumeGroupName string, volumeIDs []string) (*proto.CreateVolumeGroupResponse, error)
// ModifyVolumeGroupMembershipMock mock ModifyVolumeGroupMembership RPC call.
ModifyVolumeGroupMembershipMock func(volumeGroupID string, volumeIDs []string) (*proto.ModifyVolumeGroupMembershipResponse, error)
// DeleteVolumeGroupMock mocks DeleteVolumeGroup RPC call.
DeleteVolumeGroupMock func(volumeGroupID string) (*proto.DeleteVolumeGroupResponse, error)
// ControllerGetVolumeGroupMock mocks ControllerGetVolumeGroup RPC call.
ControllerGetVolumeGroupMock func(volumeGroupID string) (*proto.ControllerGetVolumeGroupResponse, error)
}

// CreateVolumeGroup calls CreateVolumeGroupMock mock function.
func (vg *VolumeGroupClient) CreateVolumeGroup(volumeGroupName string, volumeIDs []string) (*proto.CreateVolumeGroupResponse, error) {
return vg.CreateVolumeGroupMock(volumeGroupName, volumeIDs)
}

// ModifyVolumeGroupMembership calls ModifyVolumeGroupMembership mock function.
func (vg *VolumeGroupClient) ModifyVolumeGroupMembership(volumeGroupID string, volumeIDs []string) (*proto.ModifyVolumeGroupMembershipResponse, error) {
return vg.ModifyVolumeGroupMembershipMock(volumeGroupID, volumeIDs)
}

// DeleteVolumeGroup calls DeleteVolumeGroup mock function.
func (vg *VolumeGroupClient) DeleteVolumeGroup(volumeGroupID string) (*proto.DeleteVolumeGroupResponse, error) {
return vg.DeleteVolumeGroupMock(volumeGroupID)
}

// ControllerGetVolumeGroup calls ControllerGetVolumeGroup mock function.
func (vg *VolumeGroupClient) ControllerGetVolumeGroup(volumeGroupID string) (*proto.ControllerGetVolumeGroupResponse, error) {
return vg.ControllerGetVolumeGroupMock(volumeGroupID)
}
104 changes: 104 additions & 0 deletions internal/client/volumegroup-client.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
/*
Copyright 2024 The Kubernetes-CSI-Addons 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 client

import (
"context"
"time"

"github.com/csi-addons/kubernetes-csi-addons/internal/proto"

"google.golang.org/grpc"
)

type volumeGroupClient struct {
client proto.VolumeGroupControllerClient
timeout time.Duration
}

// VolumeGroup holds the methods required for volume grouping.
type VolumeGroup interface {
// CreateVolumeGroup RPC call to create a volume group.
CreateVolumeGroup(volumeGroupName string, volumeIDs []string, secretName, secretNamespace string, parameters map[string]string) (*proto.CreateVolumeGroupResponse, error)
// ModifyVolumeGroupMembership RPC call to modify the volume group.
ModifyVolumeGroupMembership(volumeGroupID string, volumeIDs []string, secretName, secretNamespace string) (*proto.ModifyVolumeGroupMembershipResponse, error)
// DeleteVolumeGroup RPC call to delete the volume group.
DeleteVolumeGroup(volumeGroupID string, secretName, secretNamespace string) (*proto.DeleteVolumeGroupResponse, error)
// ControllerGetVolumeGroup RPC call to fetch the volume group.
ControllerGetVolumeGroup(volumeGroupID string, secretName, secretNamespace string) (*proto.ControllerGetVolumeGroupResponse, error)
}

// NewReplicationClient returns VolumeGroup interface which has the RPC
// calls for grouping.
func NewVolumeGroupClient(cc *grpc.ClientConn, timeout time.Duration) VolumeGroup {
return &volumeGroupClient{client: proto.NewVolumeGroupControllerClient(cc), timeout: timeout}
}

func (vg *volumeGroupClient) CreateVolumeGroup(volumeGroupName string, volumeIDs []string, secretName, secretNamespace string,
parameters map[string]string) (*proto.CreateVolumeGroupResponse, error) {
req := &proto.CreateVolumeGroupRequest{
Name: volumeGroupName,
VolumeIds: volumeIDs,
Parameters: parameters,
SecretName: secretName,
SecretNamespace: secretNamespace,
}

createCtx, cancel := context.WithTimeout(context.Background(), vg.timeout)
defer cancel()
return vg.client.CreateVolumeGroup(createCtx, req)
}

func (vg *volumeGroupClient) ModifyVolumeGroupMembership(volumeGroupID string, volumeIDs []string,
secretName, secretNamespace string) (*proto.ModifyVolumeGroupMembershipResponse, error) {
req := &proto.ModifyVolumeGroupMembershipRequest{
VolumeGroupId: volumeGroupID,
VolumeIds: volumeIDs,
SecretName: secretName,
SecretNamespace: secretNamespace,
}

createCtx, cancel := context.WithTimeout(context.Background(), vg.timeout)
defer cancel()
return vg.client.ModifyVolumeGroupMembership(createCtx, req)
}

func (vg *volumeGroupClient) DeleteVolumeGroup(volumeGroupID string,
secretName, secretNamespace string) (*proto.DeleteVolumeGroupResponse, error) {
req := &proto.DeleteVolumeGroupRequest{
VolumeGroupId: volumeGroupID,
SecretName: secretName,
SecretNamespace: secretNamespace,
}

createCtx, cancel := context.WithTimeout(context.Background(), vg.timeout)
defer cancel()
return vg.client.DeleteVolumeGroup(createCtx, req)
}

func (vg *volumeGroupClient) ControllerGetVolumeGroup(volumeGroupID string,
secretName, secretNamespace string) (*proto.ControllerGetVolumeGroupResponse, error) {
req := &proto.ControllerGetVolumeGroupRequest{
VolumeGroupId: volumeGroupID,
SecretName: secretName,
SecretNamespace: secretNamespace,
}

createCtx, cancel := context.WithTimeout(context.Background(), vg.timeout)
defer cancel()
return vg.client.ControllerGetVolumeGroup(createCtx, req)
}
125 changes: 125 additions & 0 deletions internal/client/volumegroup-client_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
/*
Copyright 2024 The Kubernetes-CSI-Addons 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 client

import (
"errors"
"testing"

"github.com/csi-addons/kubernetes-csi-addons/internal/client/fake"
"github.com/csi-addons/kubernetes-csi-addons/internal/proto"

"github.com/stretchr/testify/assert"
)

func TestCreateVolumeGroup(t *testing.T) {
t.Parallel()
mockedCreateVolumeGroup := &fake.VolumeGroupClient{
CreateVolumeGroupMock: func(volumeGroupName string, volumeIDs []string) (*proto.CreateVolumeGroupResponse, error) {
return &proto.CreateVolumeGroupResponse{}, nil
},
}
client := mockedCreateVolumeGroup
resp, err := client.CreateVolumeGroup("", nil)
assert.Equal(t, &proto.CreateVolumeGroupResponse{}, resp)
assert.Nil(t, err)

// return error
mockedCreateVolumeGroup = &fake.VolumeGroupClient{
CreateVolumeGroupMock: func(volumeGroupName string, volumeIDs []string) (*proto.CreateVolumeGroupResponse, error) {
return nil, errors.New("failed to create volume group")
},
}
client = mockedCreateVolumeGroup
resp, err = client.CreateVolumeGroup("", nil)
assert.Nil(t, resp)
assert.NotNil(t, err)
}

func TestDeleteVolumeGroup(t *testing.T) {
t.Parallel()
mockedDeleteVolumeGroup := &fake.VolumeGroupClient{
DeleteVolumeGroupMock: func(volumeGroupID string) (*proto.DeleteVolumeGroupResponse, error) {
return &proto.DeleteVolumeGroupResponse{}, nil
},
}
client := mockedDeleteVolumeGroup
resp, err := client.DeleteVolumeGroup("")
assert.Equal(t, &proto.DeleteVolumeGroupResponse{}, resp)
assert.Nil(t, err)

// return error
mockedDeleteVolumeGroup = &fake.VolumeGroupClient{
DeleteVolumeGroupMock: func(volumeGroupID string) (*proto.DeleteVolumeGroupResponse, error) {
return nil, errors.New("failed to delete volume group")
},
}
client = mockedDeleteVolumeGroup
resp, err = client.DeleteVolumeGroup("")
assert.Nil(t, resp)
assert.NotNil(t, err)
}

func TestModifyVolumeGroupMembership(t *testing.T) {
t.Parallel()
// return success response
mockedModifyVolumeGroup := &fake.VolumeGroupClient{
ModifyVolumeGroupMembershipMock: func(volumeGroupID string, volumeIDs []string) (*proto.ModifyVolumeGroupMembershipResponse, error) {
return &proto.ModifyVolumeGroupMembershipResponse{}, nil
},
}
client := mockedModifyVolumeGroup
resp, err := client.ModifyVolumeGroupMembership("", nil)
assert.Equal(t, &proto.ModifyVolumeGroupMembershipResponse{}, resp)
assert.Nil(t, err)

// return error
mockedModifyVolumeGroup = &fake.VolumeGroupClient{
ModifyVolumeGroupMembershipMock: func(volumeGroupID string, volumeIDs []string) (*proto.ModifyVolumeGroupMembershipResponse, error) {
return nil, errors.New("failed to modify volume group")
},
}
client = mockedModifyVolumeGroup
resp, err = client.ModifyVolumeGroupMembership("", nil)
assert.Nil(t, resp)
assert.NotNil(t, err)
}

func TestControllerGetVolumeGroup(t *testing.T) {
t.Parallel()
// return success response
mockedGetVolumeGroup := &fake.VolumeGroupClient{
ControllerGetVolumeGroupMock: func(volumeGroupID string) (*proto.ControllerGetVolumeGroupResponse, error) {
return &proto.ControllerGetVolumeGroupResponse{}, nil
},
}
client := mockedGetVolumeGroup
resp, err := client.ControllerGetVolumeGroup("")
assert.Equal(t, &proto.ControllerGetVolumeGroupResponse{}, resp)
assert.Nil(t, err)

// return error
mockedGetVolumeGroup = &fake.VolumeGroupClient{
ControllerGetVolumeGroupMock: func(volumeGroupID string) (*proto.ControllerGetVolumeGroupResponse, error) {
return nil, errors.New("failed to get volume group")
},
}
client = mockedGetVolumeGroup
resp, err = client.ControllerGetVolumeGroup("")
assert.Nil(t, resp)
assert.NotNil(t, err)
}
2 changes: 2 additions & 0 deletions internal/proto/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
// +generate protoc --go_out=. --go_opt=paths=source_relative --go-grpc_out=. --go-grpc_opt=paths=source_relative replication.proto
//go:generate protoc --go_out=. --go_opt=paths=source_relative --go-grpc_out=. --go-grpc_opt=paths=source_relative encryptionkeyrotation.proto
// +generate protoc --go_out=. --go_opt=paths=source_relative --go-grpc_out=. --go-grpc_opt=paths=source_relative encryptionkeyrotation.proto
//go:generate protoc --go_out=. --go_opt=paths=source_relative --go-grpc_out=. --go-grpc_opt=paths=source_relative volumegroup.proto
// +generate protoc --go_out=. --go_opt=paths=source_relative --go-grpc_out=. --go-grpc_opt=paths=source_relative volumegroup.proto

/*
Copyright 2022 The Kubernetes-CSI-Addons Authors.
Expand Down
Loading

0 comments on commit 8dfe24b

Please sign in to comment.