Skip to content

Commit

Permalink
modified after review
Browse files Browse the repository at this point in the history
  • Loading branch information
davnerson-dn committed Mar 17, 2024
1 parent be4ea3a commit e0aa86d
Show file tree
Hide file tree
Showing 13 changed files with 794 additions and 484 deletions.
5 changes: 0 additions & 5 deletions deploy/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -1141,7 +1141,6 @@ func init() {
}

type CdnosSpec struct {
ManifestDir string `yaml:"manifests"`
Operator string `yaml:"operator" kne:"yaml"`
OperatorData []byte
kClient kubernetes.Interface
Expand All @@ -1166,10 +1165,6 @@ func (c *CdnosSpec) Deploy(ctx context.Context) error {
}
c.Operator = f.Name()
}
if c.Operator == "" && c.ManifestDir != "" {
log.Errorf("Deploying Cdnos controller using the directory 'manifests' field (%v) is deprecated, instead provide the filepath of the operator file directly using the 'operator' field going forward", c.ManifestDir)
c.Operator = filepath.Join(c.ManifestDir, "manifest.yaml")
}
log.Infof("Deploying Cdnos controller from: %s", c.Operator)
if err := run.LogCommand("kubectl", "apply", "-f", c.Operator); err != nil {
return fmt.Errorf("failed to deploy cdnos operator: %w", err)
Expand Down
167 changes: 167 additions & 0 deletions deploy/deploy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1843,6 +1843,173 @@ func TestLemmingSpec(t *testing.T) {
}
}

func TestCdnosSpec(t *testing.T) {
canceledCtx, cancel := context.WithCancel(context.Background())
cancel()
deploymentName := "foo"
deploymentNS := "cdnos-operator"
var replicas int32 = 2
d := &appsv1.Deployment{
ObjectMeta: metav1.ObjectMeta{
Name: deploymentName,
Namespace: deploymentNS,
},
}
tests := []struct {
desc string
cdnos *CdnosSpec
resp []fexec.Response
dErr string
hErr string
ctx context.Context
mockKClient func(*fake.Clientset)
}{{
desc: "1 replica",
cdnos: &CdnosSpec{},
resp: []fexec.Response{
{Cmd: "kubectl", Args: []string{"apply", "-f", ""}},
},

mockKClient: func(k *fake.Clientset) {
reaction := func(action ktest.Action) (handled bool, ret watch.Interface, err error) {
f := newFakeWatch([]watch.Event{{
Type: watch.Added,
Object: &appsv1.Deployment{
ObjectMeta: metav1.ObjectMeta{
Name: deploymentName,
Namespace: deploymentNS,
},
Status: appsv1.DeploymentStatus{
AvailableReplicas: 0,
ReadyReplicas: 0,
Replicas: 0,
UnavailableReplicas: 1,
UpdatedReplicas: 0,
},
},
}, {
Type: watch.Modified,
Object: &appsv1.Deployment{
ObjectMeta: metav1.ObjectMeta{
Name: deploymentName,
Namespace: deploymentNS,
},
Status: appsv1.DeploymentStatus{
AvailableReplicas: 1,
ReadyReplicas: 1,
Replicas: 1,
UnavailableReplicas: 0,
UpdatedReplicas: 1,
},
},
}})
return true, f, nil
}
k.PrependWatchReactor("deployments", reaction)
},
}, {
desc: "2 replicas - data over file",
cdnos: &CdnosSpec{
OperatorData: []byte("some fake data"),
},
resp: []fexec.Response{
{Cmd: "kubectl", Args: []string{"apply", "-f", ".*.yaml"}},
},
mockKClient: func(k *fake.Clientset) {
reaction := func(action ktest.Action) (handled bool, ret watch.Interface, err error) {
f := newFakeWatch([]watch.Event{{
Type: watch.Added,
Object: &appsv1.Deployment{
ObjectMeta: metav1.ObjectMeta{
Name: deploymentName,
Namespace: deploymentNS,
},
Spec: appsv1.DeploymentSpec{
Replicas: &replicas,
},
Status: appsv1.DeploymentStatus{
AvailableReplicas: 0,
ReadyReplicas: 0,
Replicas: 0,
UnavailableReplicas: replicas,
UpdatedReplicas: 0,
},
},
}, {
Type: watch.Modified,
Object: &appsv1.Deployment{
ObjectMeta: metav1.ObjectMeta{
Name: deploymentName,
Namespace: deploymentNS,
},
Spec: appsv1.DeploymentSpec{
Replicas: &replicas,
},
Status: appsv1.DeploymentStatus{
AvailableReplicas: replicas,
ReadyReplicas: replicas,
Replicas: replicas,
UnavailableReplicas: 0,
UpdatedReplicas: replicas,
},
},
}})
return true, f, nil
}
k.PrependWatchReactor("deployments", reaction)
},
}, {
desc: "operator deploy error",
cdnos: &CdnosSpec{},
resp: []fexec.Response{
{Cmd: "kubectl", Args: []string{"apply", "-f", ""}, Err: "failed to apply operator"},
},

dErr: "failed to apply operator",
}, {
desc: "context canceled",
cdnos: &CdnosSpec{},
resp: []fexec.Response{
{Cmd: "kubectl", Args: []string{"apply", "-f", ""}},
},

ctx: canceledCtx,
hErr: "context canceled",
}}
for _, tt := range tests {
t.Run(tt.desc, func(t *testing.T) {
if verbose {
fexec.LogCommand = func(s string) {
t.Logf("%s: %s", tt.desc, s)
}
}
cmds := fexec.Commands(tt.resp)
kexec.Command = cmds.Command
defer checkCmds(t, cmds)

ki := fake.NewSimpleClientset(d)
if tt.mockKClient != nil {
tt.mockKClient(ki)
}
tt.cdnos.SetKClient(ki)
err := tt.cdnos.Deploy(context.Background())
if s := errdiff.Substring(err, tt.dErr); s != "" {
t.Fatalf("unexpected error: %s", s)
}
if err != nil {
return
}
if tt.ctx == nil {
tt.ctx = context.Background()
}
err = tt.cdnos.Healthy(tt.ctx)
if s := errdiff.Substring(err, tt.hErr); s != "" {
t.Fatalf("unexpected error: %s", s)
}
})
}
}

func checkCmds(t *testing.T, cmds *fexec.Command) {
t.Helper()
if err := cmds.Done(); err != nil {
Expand Down
33 changes: 33 additions & 0 deletions deploy/kne/external-multinode-cdnos.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# external-multinode.yaml cluster config file sets up ingress, cni, and controllers in an existing k8 cluster.
# This spec instructs Metallb to use a docker network named multinode.
# The "external" cluster lifecycle is not managed by the KNE deployment.
cluster:
kind: External
spec:
network: multinode
ingress:
kind: MetalLB
spec:
manifest: ../../manifests/metallb/manifest.yaml
ip_count: 200
cni:
kind: Meshnet
spec:
manifest: ../../manifests/meshnet/grpc/manifest.yaml
controllers:
- kind: IxiaTG
spec:
operator: ../../manifests/keysight/ixiatg-operator.yaml
configMap: ../../manifests/keysight/ixiatg-configmap.yaml
- kind: SRLinux
spec:
operator: ../../manifests/controllers/srlinux/manifest.yaml
- kind: CEOSLab
spec:
operator: ../../manifests/controllers/ceoslab/manifest.yaml
- kind: Lemming
spec:
operator: ../../manifests/controllers/lemming/manifest.yaml
- kind: Cdnos
spec:
operator: ../../manifests/controllers/cdnos/manifest.yaml
3 changes: 0 additions & 3 deletions deploy/kne/external-multinode.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,3 @@ controllers:
- kind: Lemming
spec:
operator: ../../manifests/controllers/lemming/manifest.yaml
- kind: Cdnos
spec:
operator: ../../manifests/controllers/cdnos/manifest.yaml
39 changes: 39 additions & 0 deletions deploy/kne/kind-bridge-cdnos.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# kind-bridge.yaml cluster config file sets up a kind cluster where default PTP CNI plugin
# is swapped with the Bridge CNI plugin.
# Bridge CNI plugin is required by some Network OSes to operate.
cluster:
kind: Kind
spec:
name: kne
recycle: True
version: v0.17.0
image: kindest/node:v1.26.0
config: ../../manifests/kind/config.yaml
additionalManifests:
- ../../manifests/kind/bridge.yaml
ingress:
kind: MetalLB
spec:
manifest: ../../manifests/metallb/manifest.yaml
ip_count: 100
cni:
kind: Meshnet
spec:
manifest: ../../manifests/meshnet/grpc/manifest.yaml
controllers:
- kind: IxiaTG
spec:
operator: ../../manifests/keysight/ixiatg-operator.yaml
configMap: ../../manifests/keysight/ixiatg-configmap.yaml
- kind: SRLinux
spec:
operator: ../../manifests/controllers/srlinux/manifest.yaml
- kind: CEOSLab
spec:
operator: ../../manifests/controllers/ceoslab/manifest.yaml
- kind: Lemming
spec:
operator: ../../manifests/controllers/lemming/manifest.yaml
- kind: Cdnos
spec:
operator: ../../manifests/controllers/cdnos/manifest.yaml
3 changes: 0 additions & 3 deletions deploy/kne/kind-bridge.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,3 @@ controllers:
- kind: Lemming
spec:
operator: ../../manifests/controllers/lemming/manifest.yaml
- kind: Cdnos
spec:
operator: ../../manifests/controllers/cdnos/manifest.yaml
9 changes: 1 addition & 8 deletions docs/create_topology.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,16 +117,9 @@ Field | Type | Description

Field | Type | Description
------ | --------- | ----------------------------------------------------
`kind` | string | Name of the controller type. The current options currently are `Cdnos`, `IxiaTG`, `SRLinux`, `CEOSLab`, and `Lemming`.
`kind` | string | Name of the controller type. The current options currently are `IxiaTG`, `SRLinux`, `CEOSLab`, and `Lemming`.
`spec` | yaml.Node | Fields that set the options for the controller type.

##### Cdnos

Field | Type | Description
--------------- | ---------- | -----------
`operator` | string | Path of the yaml file to create a Cdnos operator in the cluster. The validated operator for use with KNE can be found [here](https://github.com/openconfig/kne/tree/main/manifests/controllers/cdnos/manifest.yaml).
~~`manifests`~~ | ~~string~~ | ~~Path of the directory holding the manifests to create a CEOSLab operator in the cluster. The directory is expected to contain a file with the name `manifest.yaml`.~~

##### IxiaTG

Field | Type | Description
Expand Down
1 change: 0 additions & 1 deletion examples/drivenets/srlinux.cfg

This file was deleted.

Loading

0 comments on commit e0aa86d

Please sign in to comment.