From b1ea797985d6e0fc68b97bdddf7a8e67d53f75b4 Mon Sep 17 00:00:00 2001 From: Simon Peccaud Date: Tue, 11 Jun 2024 17:13:46 +0200 Subject: [PATCH] first pass at overloading specsFile with cli opt values --- apis/v1alpha1/topology.go | 6 +++--- apis/v1alpha1/topologyspec.go | 6 +++--- clabverter/assets/topology.yaml.template | 1 - clabverter/clabverter.go | 15 +++++++++------ clabverter/clabverter_test.go | 12 ++++++------ .../test-fixtures/clabversiontest/specs.yaml | 6 +++++- .../simple-no-explicit-namespace/topo01.yaml | 2 +- .../test-fixtures/golden/simple/topo01.yaml | 5 ++--- 8 files changed, 29 insertions(+), 24 deletions(-) diff --git a/apis/v1alpha1/topology.go b/apis/v1alpha1/topology.go index ec9f6dd..af90c19 100644 --- a/apis/v1alpha1/topology.go +++ b/apis/v1alpha1/topology.go @@ -44,7 +44,7 @@ type TopologySpec struct { // ImagePull holds configurations relevant to how clabernetes launcher pods handle pulling // images. // +optional - ImagePull ImagePull `json:"imagePull"` + ImagePull ImagePull `json:"imagePull,omitempty"` // Naming tells the clabernetes controller how it should name resources it creates -- that is // whether it should include the containerlab topology name as a prefix on resources spawned // from this Topology or not; this includes the actual (containerlab) node Deployment(s), as @@ -60,14 +60,14 @@ type TopologySpec struct { // +kubebuilder:validation:XValidation:rule="self == oldSelf",message="naming field is immutable, to change this value delete and re-create the Topology" // +kubebuilder:validation:Enum=prefixed;non-prefixed;global // +kubebuilder:default=global - Naming string `json:"naming"` + Naming string `json:"naming,omitempty"` // Connectivity defines the type of connectivity to use between nodes in the topology. The // default behavior is to use vxlan tunnels, alternatively you can enable a more experimental // "slurpeeth" connectivity flavor that stuffs traffic into tcp tunnels to avoid any vxlan mtu // and/or fragmentation challenges. // +kubebuilder:validation:Enum=vxlan;slurpeeth // +kubebuilder:default=vxlan - Connectivity string `json:"connectivity"` + Connectivity string `json:"connectivity,omitempty"` } // TopologyStatus is the status for a Topology resource. diff --git a/apis/v1alpha1/topologyspec.go b/apis/v1alpha1/topologyspec.go index 48fef5d..a2859a9 100644 --- a/apis/v1alpha1/topologyspec.go +++ b/apis/v1alpha1/topologyspec.go @@ -72,7 +72,7 @@ type Expose struct { // DisableExpose indicates if exposing nodes via LoadBalancer service should be disabled, by // default any mapped ports in a containerlab topology will be exposed. // +optional - DisableExpose bool `json:"disableExpose"` + DisableExpose bool `json:"disableExpose,omitempty"` // DisableAutoExpose disables the automagic exposing of ports for a given topology. When this // setting is disabled clabernetes will not auto add ports so if you want to expose (via a // load balancer service) you will need to have ports outlined in your containerlab config @@ -132,7 +132,7 @@ type Deployment struct { // the configmap is mounted in its entirety (like normal k8s things), so you *probably* want // to specify the sub path unless you are sure what you're doing! // +optional - FilesFromConfigMap map[string][]FileFromConfigMap `json:"filesFromConfigMap"` + FilesFromConfigMap map[string][]FileFromConfigMap `json:"filesFromConfigMap,omitempty"` // FilesFromURL is a mapping of FileFromURL that define a URL at which to fetch a file, and path // on a launcher node that the file should be downloaded to. This is useful for configs that are // larger than the ConfigMap (etcd) 1Mb size limit. @@ -273,7 +273,7 @@ type ImagePull struct { // InsecureRegistries is a slice of strings of insecure registries to configure in the launcher // pods. // +optional - InsecureRegistries InsecureRegistries `json:"insecureRegistries"` + InsecureRegistries InsecureRegistries `json:"insecureRegistries,omitempty"` // PullThroughOverride allows for overriding the image pull through mode for this // particular topology. // +kubebuilder:validation:Enum=auto;always;never diff --git a/clabverter/assets/topology.yaml.template b/clabverter/assets/topology.yaml.template index 86b9618..0916521 100644 --- a/clabverter/assets/topology.yaml.template +++ b/clabverter/assets/topology.yaml.template @@ -55,7 +55,6 @@ spec: {{- if .Naming }} naming: {{ .Naming }} {{- end }} - connectivity: vxlan definition: containerlab: |- {{- .ClabConfig }} \ No newline at end of file diff --git a/clabverter/clabverter.go b/clabverter/clabverter.go index 704ccb5..01076f2 100644 --- a/clabverter/clabverter.go +++ b/clabverter/clabverter.go @@ -531,23 +531,23 @@ func (c *Clabverter) mergeConfigSpecWithRenderedTopology( return nil, err } - topologySpecFromSpecsFile := &clabernetesapisv1alpha1.TopologySpec{} + topologySpecFromTopoSpecsFile := &clabernetesapisv1alpha1.TopologySpec{} - err = sigsyaml.Unmarshal(content, topologySpecFromSpecsFile) + err = sigsyaml.Unmarshal(content, topologySpecFromTopoSpecsFile) if err != nil { return nil, err } - topologyFromSpecsFile := &clabernetesapisv1alpha1.Topology{ - Spec: *topologySpecFromSpecsFile, + topologyFromTopoSpecsFile := &clabernetesapisv1alpha1.Topology{ + Spec: *topologySpecFromTopoSpecsFile, } - topologyFromSpecsFileBytes, err := sigsyaml.Marshal(topologyFromSpecsFile) + topologyFromTopoSpecsFileBytes, err := sigsyaml.Marshal(topologyFromTopoSpecsFile) if err != nil { return nil, err } - err = sigsyaml.Unmarshal(topologyFromSpecsFileBytes, finalTopology) + err = sigsyaml.Unmarshal(topologyFromTopoSpecsFileBytes, finalTopology) if err != nil { return nil, err } @@ -562,6 +562,9 @@ func (c *Clabverter) mergeConfigSpecWithRenderedTopology( return nil, err } + // add yaml start document chars + finalTopologyBytes = append([]byte("---\n"), finalTopologyBytes...) + return finalTopologyBytes, nil } diff --git a/clabverter/clabverter_test.go b/clabverter/clabverter_test.go index 5694a6c..48522e2 100644 --- a/clabverter/clabverter_test.go +++ b/clabverter/clabverter_test.go @@ -22,7 +22,7 @@ func TestClabvert(t *testing.T) { cases := []struct { name string topologyFile string - specsFile string + topoSpecsFile string destinationNamespace string insecureRegistries string imagePullSecrets string @@ -33,19 +33,19 @@ func TestClabvert(t *testing.T) { { name: "simple", topologyFile: "test-fixtures/clabversiontest/clab.yaml", - specsFile: "", + topoSpecsFile: "", destinationNamespace: "notclabernetes", insecureRegistries: "1.2.3.4", - imagePullSecrets: "", + imagePullSecrets: "regcred", naming: "prefixed", containerlabVersion: "", }, { name: "simple-no-explicit-namespace", topologyFile: "test-fixtures/clabversiontest/clab.yaml", - specsFile: "test-fixtures/clabversiontest/specs.yaml", + topoSpecsFile: "test-fixtures/clabversiontest/specs.yaml", insecureRegistries: "1.2.3.4", - imagePullSecrets: "regcred", + imagePullSecrets: "", disableExpose: true, naming: "non-prefixed", containerlabVersion: "0.51.0", @@ -90,7 +90,7 @@ func TestClabvert(t *testing.T) { clabverter := clabernetesclabverter.MustNewClabverter( testCase.topologyFile, - testCase.specsFile, + testCase.topoSpecsFile, actualDir, testCase.destinationNamespace, testCase.naming, diff --git a/clabverter/test-fixtures/clabversiontest/specs.yaml b/clabverter/test-fixtures/clabversiontest/specs.yaml index 9182165..ba8a088 100644 --- a/clabverter/test-fixtures/clabversiontest/specs.yaml +++ b/clabverter/test-fixtures/clabversiontest/specs.yaml @@ -1,8 +1,12 @@ --- +connectivity: slurpeeth +imagePull: + pullSecrets: + - regcred statusProbes: enabled: true excludedNodes: - baguette probeConfiguration: tcpProbeConfiguration: - port: 22 + port: 22 \ No newline at end of file diff --git a/clabverter/test-fixtures/golden/simple-no-explicit-namespace/topo01.yaml b/clabverter/test-fixtures/golden/simple-no-explicit-namespace/topo01.yaml index 28248af..8f72af6 100755 --- a/clabverter/test-fixtures/golden/simple-no-explicit-namespace/topo01.yaml +++ b/clabverter/test-fixtures/golden/simple-no-explicit-namespace/topo01.yaml @@ -5,7 +5,7 @@ metadata: name: topo01 namespace: c9s-topo01 spec: - connectivity: vxlan + connectivity: slurpeeth definition: containerlab: |- name: topo01 diff --git a/clabverter/test-fixtures/golden/simple/topo01.yaml b/clabverter/test-fixtures/golden/simple/topo01.yaml index 0c97667..562929a 100755 --- a/clabverter/test-fixtures/golden/simple/topo01.yaml +++ b/clabverter/test-fixtures/golden/simple/topo01.yaml @@ -5,7 +5,6 @@ metadata: name: topo01 namespace: notclabernetes spec: - connectivity: vxlan definition: containerlab: |- name: topo01 @@ -87,11 +86,11 @@ spec: tolerations: null expose: disableAutoExpose: false - disableExpose: false imagePull: insecureRegistries: - 1.2.3.4 - pullSecrets: null + pullSecrets: + - regcred naming: prefixed statusProbes: enabled: false