Skip to content

Commit

Permalink
test: receive clusterid and take secrets as a single option
Browse files Browse the repository at this point in the history
Signed-off-by: karthik-us <ksubrahm@redhat.com>
  • Loading branch information
karthik-us committed Jul 25, 2023
1 parent ce74fe6 commit 0e064f6
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 25 deletions.
26 changes: 13 additions & 13 deletions cmd/csi-addons/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,34 +10,34 @@ similar to:
```console
$ kubectl exec -c csi-addons csi-backend-nodeplugin -- csi-addons -h
-cidrs string
comma separated list of cidrs to fence/unfence
comma separated list of cidrs to fence/unfence
-clusterid string
clusterID to fence/unfence
-drivername string
name of the CSI driver
name of the CSI driver
-endpoint string
CSI-Addons endpoint (default "unix:///tmp/csi-addons.sock")
CSI-Addons endpoint (default "unix:///tmp/csi-addons.sock")
-legacy
use legacy format for old Kubernetes versions
use legacy format for old Kubernetes versions
-operation string
csi-addons operation
csi-addons operation
-persistentvolume string
name of the PersistentVolume
-secretname string
name of the kubernetes secret
-secretnamespace string
namespace of the kubernetes secret
name of the PersistentVolume
-secret namespace/name
kubernetes secret in the format namespace/name
-stagingpath string
staging path (default "/var/lib/kubelet/plugins/kubernetes.io/csi/")
staging path (default "/var/lib/kubelet/plugins/kubernetes.io/csi/")
-version
print Version details
print Version details

The following operations are supported:
- ControllerReclaimSpace
- NodeReclaimSpace
- GetIdentity
- GetCapabilities
- Probe
- NetworkFence
- NetworkUnFence
- ControllerReclaimSpace
```

The above command assumes the running `csi-backend-nodeplugin` Pod has the
Expand Down
8 changes: 4 additions & 4 deletions cmd/csi-addons/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ type command struct {
operation string
persistentVolume string
drivername string
secretName string
secretNamespace string
secret string
cidrs string
clusterid string
legacy bool
}

Expand All @@ -59,9 +59,9 @@ func init() {
flag.StringVar(&cmd.operation, "operation", "", "csi-addons operation")
flag.StringVar(&cmd.persistentVolume, "persistentvolume", "", "name of the PersistentVolume")
flag.StringVar(&cmd.drivername, "drivername", "", "name of the CSI driver")
flag.StringVar(&cmd.secretName, "secretname", "", "name of the kubernetes secret")
flag.StringVar(&cmd.secretNamespace, "secretnamespace", "", "namespace of the kubernetes secret")
flag.StringVar(&cmd.secret, "secret", "", "kubernetes secret in the format `namespace/name`")
flag.StringVar(&cmd.cidrs, "cidrs", "", "comma separated list of cidrs to fence/unfence")
flag.StringVar(&cmd.clusterid, "clusterid", "", "clusterID to fence/unfence")
flag.BoolVar(&cmd.legacy, "legacy", false, "use legacy format for old Kubernetes versions")
flag.BoolVar(&showVersion, "version", false, "print Version details")

Expand Down
40 changes: 32 additions & 8 deletions cmd/csi-addons/networkfence.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ type NetworkFenceServer struct {
// inherit Connect() and Close() from type grpcClient
grpcClient

parameters map[string]string
secretName string
secretNamespace string
cidrs []string
Expand All @@ -38,16 +39,26 @@ type NetworkFenceServer struct {
var _ = registerOperation("NetworkFence", &NetworkFenceServer{})

func (ns *NetworkFenceServer) Init(c *command) error {
ns.secretName = c.secretName
if ns.secretName == "" {
return fmt.Errorf("secret name is not set")
ns.parameters = make(map[string]string)
ns.parameters["clusterID"] = c.clusterid
if ns.parameters["clusterID"] == "" {
return fmt.Errorf("clusterID not set")
}

ns.secretNamespace = c.secretNamespace
secrets := strings.Split(c.secret, "/")
if len(secrets) != 2 {
return fmt.Errorf("secret should be specified in the format `namespace/name`")
}
ns.secretNamespace = secrets[0]
if ns.secretNamespace == "" {
return fmt.Errorf("secret namespace is not set")
}

ns.secretName = secrets[1]
if ns.secretName == "" {
return fmt.Errorf("secret name is not set")
}

ns.cidrs = (strings.Split(c.cidrs, ","))
if len(ns.cidrs) == 0 || (len(ns.cidrs) == 1 && ns.cidrs[0] == "") {
return fmt.Errorf("cidrs not set")
Expand All @@ -61,6 +72,7 @@ func (ns *NetworkFenceServer) Execute() error {
nfs := service.NewNetworkFenceServer(ns.Client, k)

req := &proto.NetworkFenceRequest{
Parameters: ns.parameters,
SecretName: ns.secretName,
SecretNamespace: ns.secretNamespace,
Cidrs: ns.cidrs,
Expand All @@ -80,6 +92,7 @@ type NetworkUnFenceServer struct {
// inherit Connect() and Close() from type grpcClient
grpcClient

parameters map[string]string
secretName string
secretNamespace string
cidrs []string
Expand All @@ -88,16 +101,26 @@ type NetworkUnFenceServer struct {
var _ = registerOperation("NetworkUnFence", &NetworkUnFenceServer{})

func (ns *NetworkUnFenceServer) Init(c *command) error {
ns.secretName = c.secretName
if ns.secretName == "" {
return fmt.Errorf("secret name is not set")
ns.parameters = make(map[string]string)
ns.parameters["clusterID"] = c.clusterid
if ns.parameters["clusterID"] == "" {
return fmt.Errorf("clusterID not set")
}

ns.secretNamespace = c.secretNamespace
secrets := strings.Split(c.secret, "/")
if len(secrets) != 2 {
return fmt.Errorf("secret should be specified in the format `namespace/name`")
}
ns.secretNamespace = secrets[0]
if ns.secretNamespace == "" {
return fmt.Errorf("secret namespace is not set")
}

ns.secretName = secrets[1]
if ns.secretName == "" {
return fmt.Errorf("secret names is not set")
}

ns.cidrs = strings.Split(c.cidrs, ",")
if len(ns.cidrs) == 0 || (len(ns.cidrs) == 1 && ns.cidrs[0] == "") {
return fmt.Errorf("cidrs not set")
Expand All @@ -111,6 +134,7 @@ func (ns *NetworkUnFenceServer) Execute() error {
nfs := service.NewNetworkFenceServer(ns.Client, k)

req := &proto.NetworkFenceRequest{
Parameters: ns.parameters,
SecretName: ns.secretName,
SecretNamespace: ns.secretNamespace,
Cidrs: ns.cidrs,
Expand Down

0 comments on commit 0e064f6

Please sign in to comment.