Skip to content

Commit

Permalink
first pass at overloading specsFile with cli opt values
Browse files Browse the repository at this point in the history
  • Loading branch information
Simon Peccaud committed Jun 11, 2024
1 parent 8895ad0 commit b1ea797
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 24 deletions.
6 changes: 3 additions & 3 deletions apis/v1alpha1/topology.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand Down
6 changes: 3 additions & 3 deletions apis/v1alpha1/topologyspec.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion clabverter/assets/topology.yaml.template
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ spec:
{{- if .Naming }}
naming: {{ .Naming }}
{{- end }}
connectivity: vxlan
definition:
containerlab: |-
{{- .ClabConfig }}
15 changes: 9 additions & 6 deletions clabverter/clabverter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -562,6 +562,9 @@ func (c *Clabverter) mergeConfigSpecWithRenderedTopology(
return nil, err
}

// add yaml start document chars
finalTopologyBytes = append([]byte("---\n"), finalTopologyBytes...)

return finalTopologyBytes, nil
}

Expand Down
12 changes: 6 additions & 6 deletions clabverter/clabverter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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",
Expand Down Expand Up @@ -90,7 +90,7 @@ func TestClabvert(t *testing.T) {

clabverter := clabernetesclabverter.MustNewClabverter(
testCase.topologyFile,
testCase.specsFile,
testCase.topoSpecsFile,
actualDir,
testCase.destinationNamespace,
testCase.naming,
Expand Down
6 changes: 5 additions & 1 deletion clabverter/test-fixtures/clabversiontest/specs.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
---
connectivity: slurpeeth
imagePull:
pullSecrets:
- regcred
statusProbes:
enabled: true
excludedNodes:
- baguette
probeConfiguration:
tcpProbeConfiguration:
port: 22
port: 22
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ metadata:
name: topo01
namespace: c9s-topo01
spec:
connectivity: vxlan
connectivity: slurpeeth
definition:
containerlab: |-
name: topo01
Expand Down
5 changes: 2 additions & 3 deletions clabverter/test-fixtures/golden/simple/topo01.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ metadata:
name: topo01
namespace: notclabernetes
spec:
connectivity: vxlan
definition:
containerlab: |-
name: topo01
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit b1ea797

Please sign in to comment.