Skip to content

Commit 8d93f66

Browse files
Simon Peccaudcarlmontanari
authored andcommitted
first pass at overloading specsFile with cli opt values
1 parent 9d99558 commit 8d93f66

File tree

8 files changed

+29
-24
lines changed

8 files changed

+29
-24
lines changed

apis/v1alpha1/topology.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ type TopologySpec struct {
4444
// ImagePull holds configurations relevant to how clabernetes launcher pods handle pulling
4545
// images.
4646
// +optional
47-
ImagePull ImagePull `json:"imagePull"`
47+
ImagePull ImagePull `json:"imagePull,omitempty"`
4848
// Naming tells the clabernetes controller how it should name resources it creates -- that is
4949
// whether it should include the containerlab topology name as a prefix on resources spawned
5050
// from this Topology or not; this includes the actual (containerlab) node Deployment(s), as
@@ -60,14 +60,14 @@ type TopologySpec struct {
6060
// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="naming field is immutable, to change this value delete and re-create the Topology"
6161
// +kubebuilder:validation:Enum=prefixed;non-prefixed;global
6262
// +kubebuilder:default=global
63-
Naming string `json:"naming"`
63+
Naming string `json:"naming,omitempty"`
6464
// Connectivity defines the type of connectivity to use between nodes in the topology. The
6565
// default behavior is to use vxlan tunnels, alternatively you can enable a more experimental
6666
// "slurpeeth" connectivity flavor that stuffs traffic into tcp tunnels to avoid any vxlan mtu
6767
// and/or fragmentation challenges.
6868
// +kubebuilder:validation:Enum=vxlan;slurpeeth
6969
// +kubebuilder:default=vxlan
70-
Connectivity string `json:"connectivity"`
70+
Connectivity string `json:"connectivity,omitempty"`
7171
}
7272

7373
// TopologyStatus is the status for a Topology resource.

apis/v1alpha1/topologyspec.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ type Expose struct {
7272
// DisableExpose indicates if exposing nodes via LoadBalancer service should be disabled, by
7373
// default any mapped ports in a containerlab topology will be exposed.
7474
// +optional
75-
DisableExpose bool `json:"disableExpose"`
75+
DisableExpose bool `json:"disableExpose,omitempty"`
7676
// DisableAutoExpose disables the automagic exposing of ports for a given topology. When this
7777
// setting is disabled clabernetes will not auto add ports so if you want to expose (via a
7878
// load balancer service) you will need to have ports outlined in your containerlab config
@@ -132,7 +132,7 @@ type Deployment struct {
132132
// the configmap is mounted in its entirety (like normal k8s things), so you *probably* want
133133
// to specify the sub path unless you are sure what you're doing!
134134
// +optional
135-
FilesFromConfigMap map[string][]FileFromConfigMap `json:"filesFromConfigMap"`
135+
FilesFromConfigMap map[string][]FileFromConfigMap `json:"filesFromConfigMap,omitempty"`
136136
// FilesFromURL is a mapping of FileFromURL that define a URL at which to fetch a file, and path
137137
// on a launcher node that the file should be downloaded to. This is useful for configs that are
138138
// larger than the ConfigMap (etcd) 1Mb size limit.
@@ -273,7 +273,7 @@ type ImagePull struct {
273273
// InsecureRegistries is a slice of strings of insecure registries to configure in the launcher
274274
// pods.
275275
// +optional
276-
InsecureRegistries InsecureRegistries `json:"insecureRegistries"`
276+
InsecureRegistries InsecureRegistries `json:"insecureRegistries,omitempty"`
277277
// PullThroughOverride allows for overriding the image pull through mode for this
278278
// particular topology.
279279
// +kubebuilder:validation:Enum=auto;always;never

clabverter/assets/topology.yaml.template

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ spec:
5555
{{- if .Naming }}
5656
naming: {{ .Naming }}
5757
{{- end }}
58-
connectivity: vxlan
5958
definition:
6059
containerlab: |-
6160
{{- .ClabConfig }}

clabverter/clabverter.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -541,23 +541,23 @@ func (c *Clabverter) mergeConfigSpecWithRenderedTopology(
541541
return nil, err
542542
}
543543

544-
topologySpecFromSpecsFile := &clabernetesapisv1alpha1.TopologySpec{}
544+
topologySpecFromTopoSpecsFile := &clabernetesapisv1alpha1.TopologySpec{}
545545

546-
err = sigsyaml.Unmarshal(content, topologySpecFromSpecsFile)
546+
err = sigsyaml.Unmarshal(content, topologySpecFromTopoSpecsFile)
547547
if err != nil {
548548
return nil, err
549549
}
550550

551-
topologyFromSpecsFile := &StatuslessTopology{
552-
Spec: *topologySpecFromSpecsFile,
551+
topologyFromTopoSpecsFile := &StatuslessTopology{
552+
Spec: *topologySpecFromTopoSpecsFile,
553553
}
554554

555-
topologyFromSpecsFileBytes, err := sigsyaml.Marshal(topologyFromSpecsFile)
555+
topologyFromTopoSpecsFileBytes, err := sigsyaml.Marshal(topologyFromTopoSpecsFile)
556556
if err != nil {
557557
return nil, err
558558
}
559559

560-
err = sigsyaml.Unmarshal(topologyFromSpecsFileBytes, finalTopology)
560+
err = sigsyaml.Unmarshal(topologyFromTopoSpecsFileBytes, finalTopology)
561561
if err != nil {
562562
return nil, err
563563
}
@@ -572,6 +572,9 @@ func (c *Clabverter) mergeConfigSpecWithRenderedTopology(
572572
return nil, err
573573
}
574574

575+
// add yaml start document chars
576+
finalTopologyBytes = append([]byte("---\n"), finalTopologyBytes...)
577+
575578
return finalTopologyBytes, nil
576579
}
577580

clabverter/clabverter_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ func TestClabvert(t *testing.T) {
2121
cases := []struct {
2222
name string
2323
topologyFile string
24-
specsFile string
24+
topoSpecsFile string
2525
destinationNamespace string
2626
insecureRegistries string
2727
imagePullSecrets string
@@ -32,19 +32,19 @@ func TestClabvert(t *testing.T) {
3232
{
3333
name: "simple",
3434
topologyFile: "test-fixtures/clabversiontest/clab.yaml",
35-
specsFile: "",
35+
topoSpecsFile: "",
3636
destinationNamespace: "notclabernetes",
3737
insecureRegistries: "1.2.3.4",
38-
imagePullSecrets: "",
38+
imagePullSecrets: "regcred",
3939
naming: "prefixed",
4040
containerlabVersion: "",
4141
},
4242
{
4343
name: "simple-no-explicit-namespace",
4444
topologyFile: "test-fixtures/clabversiontest/clab.yaml",
45-
specsFile: "test-fixtures/clabversiontest/specs.yaml",
45+
topoSpecsFile: "test-fixtures/clabversiontest/specs.yaml",
4646
insecureRegistries: "1.2.3.4",
47-
imagePullSecrets: "regcred",
47+
imagePullSecrets: "",
4848
disableExpose: true,
4949
naming: "non-prefixed",
5050
containerlabVersion: "0.51.0",
@@ -89,7 +89,7 @@ func TestClabvert(t *testing.T) {
8989

9090
clabverter := clabernetesclabverter.MustNewClabverter(
9191
testCase.topologyFile,
92-
testCase.specsFile,
92+
testCase.topoSpecsFile,
9393
actualDir,
9494
testCase.destinationNamespace,
9595
testCase.naming,
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
---
2+
connectivity: slurpeeth
3+
imagePull:
4+
pullSecrets:
5+
- regcred
26
statusProbes:
37
enabled: true
48
excludedNodes:
59
- baguette
610
probeConfiguration:
711
tcpProbeConfiguration:
8-
port: 22
12+
port: 22

clabverter/test-fixtures/golden/simple-no-explicit-namespace/topo01.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ metadata:
55
name: topo01
66
namespace: c9s-topo01
77
spec:
8-
connectivity: vxlan
8+
connectivity: slurpeeth
99
definition:
1010
containerlab: |-
1111
name: topo01

clabverter/test-fixtures/golden/simple/topo01.yaml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ metadata:
55
name: topo01
66
namespace: notclabernetes
77
spec:
8-
connectivity: vxlan
98
definition:
109
containerlab: |-
1110
name: topo01
@@ -87,11 +86,11 @@ spec:
8786
tolerations: null
8887
expose:
8988
disableAutoExpose: false
90-
disableExpose: false
9189
imagePull:
9290
insecureRegistries:
9391
- 1.2.3.4
94-
pullSecrets: null
92+
pullSecrets:
93+
- regcred
9594
naming: prefixed
9695
statusProbes:
9796
enabled: false

0 commit comments

Comments
 (0)