-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: Adding NetworkFence capability to test tool
Adding the missing NetworkFence capability to the cmd/csi-addons admin/test tool. Fixes: #204 Signed-off-by: karthik-us <ksubrahm@redhat.com>
- Loading branch information
1 parent
0e2f548
commit 8f6091c
Showing
3 changed files
with
148 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
/* | ||
Copyright 2023 The Ceph-CSI 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 main | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/csi-addons/kubernetes-csi-addons/internal/proto" | ||
"github.com/csi-addons/kubernetes-csi-addons/internal/sidecar/service" | ||
) | ||
|
||
// NetworkFenceServer executes the NetworkFenceServer operation. | ||
type NetworkFenceServer struct { | ||
// inherit Connect() and Close() from type grpcClient | ||
grpcClient | ||
|
||
secretName string | ||
secretNamespace string | ||
cidrs []string | ||
} | ||
|
||
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.secretNamespace = c.secretNamespace | ||
if ns.secretNamespace == "" { | ||
return fmt.Errorf("secret namespace 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") | ||
} | ||
return nil | ||
} | ||
|
||
func (ns *NetworkFenceServer) Execute() error { | ||
k := getKubernetesClient() | ||
|
||
nfs := service.NewNetworkFenceServer(ns.Client, k) | ||
|
||
req := &proto.NetworkFenceRequest{ | ||
SecretName: ns.secretName, | ||
SecretNamespace: ns.secretNamespace, | ||
Cidrs: ns.cidrs, | ||
} | ||
|
||
_, err := nfs.FenceClusterNetwork(context.TODO(), req) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
fmt.Printf("Network fence successful") | ||
return nil | ||
} | ||
|
||
// NetworkUnFenceServer executes the NetworkUnFenceServer operation. | ||
type NetworkUnFenceServer struct { | ||
// inherit Connect() and Close() from type grpcClient | ||
grpcClient | ||
|
||
secretName string | ||
secretNamespace string | ||
cidrs []string | ||
} | ||
|
||
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.secretNamespace = c.secretNamespace | ||
if ns.secretNamespace == "" { | ||
return fmt.Errorf("secret namespace 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") | ||
} | ||
return nil | ||
} | ||
|
||
func (ns *NetworkUnFenceServer) Execute() error { | ||
k := getKubernetesClient() | ||
|
||
nfs := service.NewNetworkFenceServer(ns.Client, k) | ||
|
||
req := &proto.NetworkFenceRequest{ | ||
SecretName: ns.secretName, | ||
SecretNamespace: ns.secretNamespace, | ||
Cidrs: ns.cidrs, | ||
} | ||
|
||
_, err := nfs.UnFenceClusterNetwork(context.TODO(), req) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
fmt.Printf("Network unfence successful") | ||
return nil | ||
} |