Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: clab timeout option (also in global config) #136

Merged
merged 1 commit into from
Mar 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions apis/v1alpha1/configspec.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ type ConfigDeployment struct {
// This is disabled by default.
// +optional
ContainerlabDebug bool `json:"containerlabDebug"`
// ContainerlabTimeout sets the `--timeout` flag when invoking containerlab in the launcher
// pods.
// +optional
ContainerlabTimeout string `json:"containerlabTimeout"`
// ContainerlabVersion sets a custom version to use for containerlab -- when set this will cause
// the launcher pods to download and use this specific version of containerlab. Setting a bad
// version (version that doesnt exist/typo/etc.) will cause pods to fail to launch, so be
Expand Down
4 changes: 4 additions & 0 deletions apis/v1alpha1/topologyspec.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,10 @@ type Deployment struct {
// "false") will be used.
// +optional
ContainerlabDebug *bool `json:"containerlabDebug"`
// ContainerlabTimeout sets the `--timeout` flag when invoking containerlab in the launcher
// pods.
// +optional
ContainerlabTimeout string `json:"containerlabTimeout"`
// ContainerlabVersion sets a custom version to use for containerlab -- when set this will cause
// the launcher pods to download and use this specific version of containerlab. Setting a bad
// version (version that doesnt exist/typo/etc.) will cause pods to fail to launch, so be
Expand Down
4 changes: 4 additions & 0 deletions assets/crd/clabernetes.containerlab.dev_configs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ spec:
ContainerlabDebug sets the `--debug` flag when invoking containerlab in the launcher pods.
This is disabled by default.
type: boolean
containerlabTimeout:
description: ContainerlabTimeout sets the `--timeout` flag when
invoking containerlab in the launcher pods.
type: string
containerlabVersion:
description: |-
ContainerlabVersion sets a custom version to use for containerlab -- when set this will cause
Expand Down
5 changes: 5 additions & 0 deletions assets/crd/clabernetes.containerlab.dev_topologies.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ spec:
This is disabled by default. If this value is unset, the global config value (default of
"false") will be used.
type: boolean
containerlabTimeout:
description: |-
ContainerlabTimeout sets the `--timeout` flag when invoking containerlab in the launcher
pods.
type: string
containerlabVersion:
description: |-
ContainerlabVersion sets a custom version to use for containerlab -- when set this will cause
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ spec:
ContainerlabDebug sets the `--debug` flag when invoking containerlab in the launcher pods.
This is disabled by default.
type: boolean
containerlabTimeout:
description: ContainerlabTimeout sets the `--timeout` flag when
invoking containerlab in the launcher pods.
type: string
containerlabVersion:
description: |-
ContainerlabVersion sets a custom version to use for containerlab -- when set this will cause
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ spec:
This is disabled by default. If this value is unset, the global config value (default of
"false") will be used.
type: boolean
containerlabTimeout:
description: |-
ContainerlabTimeout sets the `--timeout` flag when invoking containerlab in the launcher
pods.
type: string
containerlabVersion:
description: |-
ContainerlabVersion sets a custom version to use for containerlab -- when set this will cause
Expand Down
1 change: 1 addition & 0 deletions charts/clabernetes/templates/configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ data:
{{ .Values.globalConfig.deployment.resourcesByContainerlabKind | toYaml | indent 4 }}
privilegedLauncher: "{{ .Values.globalConfig.deployment.privilegedLauncher }}"
containerlabDebug: "{{ .Values.globalConfig.deployment.containerlabDebug }}"
containerlabTimeout: {{ .Values.globalConfig.deployment.containerlabTimeout }}
inClusterDNSSuffix: {{ .Values.globalConfig.inClusterDNSSuffix }}
imagePullThroughMode: {{ .Values.globalConfig.imagePull.imagePullThroughMode }}
launcherImage: {{ .Values.globalConfig.deployment.launcherImage }}
Expand Down
3 changes: 3 additions & 0 deletions charts/clabernetes/values.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@
"containerlabDebug": {
"type": "boolean"
},
"containerlabTimeout": {
"type": "string"
},
"launcherImage": {
"type": "string"
},
Expand Down
4 changes: 4 additions & 0 deletions charts/clabernetes/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,10 @@ globalConfig:
# containerlab debug flag set.
containerlabDebug: false

# containerlabTimeout sets the global default value for the containerlab timeout value that the
# launcher pods should use.
containerlabTimeout: ""

# default image for launcher deployments; if not set here, manager will have this set to a sane
# default as an env var that will be applied (this follows same patter as the manager image
# itself), so this is here just if you want to override that yourself.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ spec:
- endpoints: ["srl1:e1-1", "srl2:e1-1"]
deployment:
containerlabDebug: null
containerlabTimeout: ""
containerlabVersion: 0.51.0
filesFromConfigMap:
srl1:
Expand Down
1 change: 1 addition & 0 deletions clabverter/test-fixtures/golden/simple/topo01.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ spec:
- endpoints: ["srl1:e1-1", "srl2:e1-1"]
deployment:
containerlabDebug: null
containerlabTimeout: ""
filesFromConfigMap:
srl1:
- configMapName: topo01-srl1-startup-config
Expand Down
6 changes: 6 additions & 0 deletions config/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ type bootstrapConfig struct {
resourcesByContainerlabKind map[string]map[string]*k8scorev1.ResourceRequirements
privilegedLauncher bool
containerlabDebug bool
containerlabTimeout string
inClusterDNSSuffix string
imagePullThroughMode string
launcherImage string
Expand Down Expand Up @@ -99,6 +100,11 @@ func bootstrapFromConfigMap( //nolint:gocyclo,funlen,gocognit
}
}

inContainerlabTimeout, inContainerlabTimeoutOk := inMap["containerlabTimeout"]
if inContainerlabTimeoutOk {
bc.containerlabTimeout = inContainerlabTimeout
}

inClusterDNSSuffix, inClusterDNSSuffixOk := inMap["inClusterDNSSuffix"]
if inClusterDNSSuffixOk {
bc.inClusterDNSSuffix = inClusterDNSSuffix
Expand Down
4 changes: 4 additions & 0 deletions config/fake.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ func (f fakeManager) GetContainerlabDebug() bool {
return false
}

func (f fakeManager) GetContainerlabTimeout() string {
return ""
}

func (f fakeManager) GetInClusterDNSSuffix() string {
return "svc.cluster.local"
}
Expand Down
7 changes: 7 additions & 0 deletions config/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,13 @@ func (m *manager) GetContainerlabDebug() bool {
return m.config.Deployment.ContainerlabDebug
}

func (m *manager) GetContainerlabTimeout() string {
m.lock.RLock()
defer m.lock.RUnlock()

return m.config.Deployment.ContainerlabTimeout
}

func (m *manager) GetInClusterDNSSuffix() string {
m.lock.RLock()
defer m.lock.RUnlock()
Expand Down
2 changes: 2 additions & 0 deletions config/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ type Manager interface {
GetPrivilegedLauncher() bool
// GetContainerlabDebug returns the global config value for containerlabDebug.
GetContainerlabDebug() bool
// GetContainerlabTimeout returns the global config containerlab timeout value.
GetContainerlabTimeout() string
// GetInClusterDNSSuffix returns the in cluster dns suffix as set by the global config.
GetInClusterDNSSuffix() string
// GetImagePullThroughMode returns the image pull through mode in the global config.
Expand Down
4 changes: 4 additions & 0 deletions constants/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ const (
// debug flag of clabernetes when invoked on the launcher pod.
LauncherContainerlabDebug = "LAUNCHER_CONTAINERLAB_DEBUG"

// LauncherContainerlabTimeout is the environment variable name that can be used to set the
// value of the timeout flag of clabernetes when invoked on the launcher pod.
LauncherContainerlabTimeout = "LAUNCHER_CONTAINERLAB_TIMEOUT"

// LauncherImageEnv env var that tells the controllers what image to use for clabernetes
// (launcher) pods.
LauncherImageEnv = "LAUNCHER_IMAGE"
Expand Down
11 changes: 10 additions & 1 deletion controllers/topology/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ func (r *DeploymentReconciler) renderDeploymentContainer(
deployment.Spec.Template.Spec.Containers = []k8scorev1.Container{container}
}

func (r *DeploymentReconciler) renderDeploymentContainerEnv(
func (r *DeploymentReconciler) renderDeploymentContainerEnv( //nolint: funlen
deployment *k8sappsv1.Deployment,
nodeName,
owningTopologyName string,
Expand Down Expand Up @@ -480,6 +480,11 @@ func (r *DeploymentReconciler) renderDeploymentContainerEnv(
containerlabVersion = r.configManagerGetter().GetContainerlabVersion()
}

containerlabTimeout := owningTopology.Spec.Deployment.ContainerlabTimeout
if containerlabTimeout == "" {
containerlabTimeout = r.configManagerGetter().GetContainerlabTimeout()
}

envs := []k8scorev1.EnvVar{
{
Name: clabernetesconstants.NodeNameEnv,
Expand Down Expand Up @@ -548,6 +553,10 @@ func (r *DeploymentReconciler) renderDeploymentContainerEnv(
Name: clabernetesconstants.LauncherContainerlabVersion,
Value: containerlabVersion,
},
{
Name: clabernetesconstants.LauncherContainerlabTimeout,
Value: containerlabTimeout,
},
}

if ResolveGlobalVsTopologyBool(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,9 @@
{
"name": "LAUNCHER_CONTAINERLAB_VERSION"
},
{
"name": "LAUNCHER_CONTAINERLAB_TIMEOUT"
},
{
"name": "LAUNCHER_CONTAINERLAB_DEBUG",
"value": "true"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,9 @@
"name": "LAUNCHER_CONTAINERLAB_VERSION",
"value": "0.51.1"
},
{
"name": "LAUNCHER_CONTAINERLAB_TIMEOUT"
},
{
"name": "LAUNCHER_PRIVILEGED",
"value": "true"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,9 @@
{
"name": "LAUNCHER_CONTAINERLAB_VERSION"
},
{
"name": "LAUNCHER_CONTAINERLAB_TIMEOUT"
},
{
"name": "LAUNCHER_PRIVILEGED",
"value": "true"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,9 @@
{
"name": "LAUNCHER_CONTAINERLAB_VERSION"
},
{
"name": "LAUNCHER_CONTAINERLAB_TIMEOUT"
},
{
"name": "LAUNCHER_INSECURE_REGISTRIES",
"value": "1.2.3.4,potato.com"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,9 @@
{
"name": "LAUNCHER_CONTAINERLAB_VERSION"
},
{
"name": "LAUNCHER_CONTAINERLAB_TIMEOUT"
},
{
"name": "LAUNCHER_PRIVILEGED",
"value": "true"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,9 @@
},
{
"name": "LAUNCHER_CONTAINERLAB_VERSION"
},
{
"name": "LAUNCHER_CONTAINERLAB_TIMEOUT"
}
],
"resources": {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,9 @@
{
"name": "LAUNCHER_CONTAINERLAB_VERSION"
},
{
"name": "LAUNCHER_CONTAINERLAB_TIMEOUT"
},
{
"name": "LAUNCHER_PRIVILEGED",
"value": "true"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,9 @@
{
"name": "LAUNCHER_CONTAINERLAB_VERSION"
},
{
"name": "LAUNCHER_CONTAINERLAB_TIMEOUT"
},
{
"name": "LAUNCHER_PRIVILEGED",
"value": "true"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,9 @@
{
"name": "LAUNCHER_CONTAINERLAB_VERSION"
},
{
"name": "LAUNCHER_CONTAINERLAB_TIMEOUT"
},
{
"name": "LAUNCHER_PRIVILEGED",
"value": "true"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ spec:
links:
- endpoints: ["srl1:e1-1", "srl2:e1-1"]
deployment:
containerlabTimeout: ""
persistence:
enabled: false
scheduling: {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ spec:
kind: srl
image: ghcr.io/nokia/srlinux
deployment:
containerlabTimeout: ""
persistence:
enabled: false
scheduling: {}
Expand Down
16 changes: 16 additions & 0 deletions generated/openapi/openapi_generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions launcher/containerlab.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,11 @@ func (c *clabernetes) runContainerlab() error {
args = append(args, "--debug")
}

containerlabTimeout := os.Getenv(clabernetesconstants.LauncherContainerlabTimeout)
if containerlabTimeout != "" {
args = append(args, []string{"--timeout", containerlabTimeout}...)
}

cmd := exec.Command("containerlab", args...)

cmd.Stdout = containerlabOutWriter
Expand Down