diff --git a/apis/v1alpha1/configspec.go b/apis/v1alpha1/configspec.go index 48b6e21..7bf59b6 100644 --- a/apis/v1alpha1/configspec.go +++ b/apis/v1alpha1/configspec.go @@ -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 diff --git a/apis/v1alpha1/topologyspec.go b/apis/v1alpha1/topologyspec.go index e98571d..332b008 100644 --- a/apis/v1alpha1/topologyspec.go +++ b/apis/v1alpha1/topologyspec.go @@ -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 diff --git a/assets/crd/clabernetes.containerlab.dev_configs.yaml b/assets/crd/clabernetes.containerlab.dev_configs.yaml index 5cd7f63..d36fbf5 100644 --- a/assets/crd/clabernetes.containerlab.dev_configs.yaml +++ b/assets/crd/clabernetes.containerlab.dev_configs.yaml @@ -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 diff --git a/assets/crd/clabernetes.containerlab.dev_topologies.yaml b/assets/crd/clabernetes.containerlab.dev_topologies.yaml index 6f2cc39..0b55208 100644 --- a/assets/crd/clabernetes.containerlab.dev_topologies.yaml +++ b/assets/crd/clabernetes.containerlab.dev_topologies.yaml @@ -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 diff --git a/charts/clabernetes/crds/clabernetes.containerlab.dev_configs.yaml b/charts/clabernetes/crds/clabernetes.containerlab.dev_configs.yaml index 5cd7f63..d36fbf5 100644 --- a/charts/clabernetes/crds/clabernetes.containerlab.dev_configs.yaml +++ b/charts/clabernetes/crds/clabernetes.containerlab.dev_configs.yaml @@ -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 diff --git a/charts/clabernetes/crds/clabernetes.containerlab.dev_topologies.yaml b/charts/clabernetes/crds/clabernetes.containerlab.dev_topologies.yaml index 6f2cc39..0b55208 100644 --- a/charts/clabernetes/crds/clabernetes.containerlab.dev_topologies.yaml +++ b/charts/clabernetes/crds/clabernetes.containerlab.dev_topologies.yaml @@ -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 diff --git a/charts/clabernetes/templates/configmap.yaml b/charts/clabernetes/templates/configmap.yaml index 88047fc..79f4084 100644 --- a/charts/clabernetes/templates/configmap.yaml +++ b/charts/clabernetes/templates/configmap.yaml @@ -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 }} diff --git a/charts/clabernetes/values.schema.json b/charts/clabernetes/values.schema.json index ba1a43b..2edf491 100644 --- a/charts/clabernetes/values.schema.json +++ b/charts/clabernetes/values.schema.json @@ -98,6 +98,9 @@ "containerlabDebug": { "type": "boolean" }, + "containerlabTimeout": { + "type": "string" + }, "launcherImage": { "type": "string" }, diff --git a/charts/clabernetes/values.yaml b/charts/clabernetes/values.yaml index e12219e..f24bb95 100644 --- a/charts/clabernetes/values.yaml +++ b/charts/clabernetes/values.yaml @@ -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. 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 6920f25..335f504 100755 --- a/clabverter/test-fixtures/golden/simple-no-explicit-namespace/topo01.yaml +++ b/clabverter/test-fixtures/golden/simple-no-explicit-namespace/topo01.yaml @@ -40,6 +40,7 @@ spec: - endpoints: ["srl1:e1-1", "srl2:e1-1"] deployment: containerlabDebug: null + containerlabTimeout: "" containerlabVersion: 0.51.0 filesFromConfigMap: srl1: diff --git a/clabverter/test-fixtures/golden/simple/topo01.yaml b/clabverter/test-fixtures/golden/simple/topo01.yaml index 5cfe1c5..f7c0fe6 100755 --- a/clabverter/test-fixtures/golden/simple/topo01.yaml +++ b/clabverter/test-fixtures/golden/simple/topo01.yaml @@ -40,6 +40,7 @@ spec: - endpoints: ["srl1:e1-1", "srl2:e1-1"] deployment: containerlabDebug: null + containerlabTimeout: "" filesFromConfigMap: srl1: - configMapName: topo01-srl1-startup-config diff --git a/config/bootstrap.go b/config/bootstrap.go index 5b7b290..17b2459 100644 --- a/config/bootstrap.go +++ b/config/bootstrap.go @@ -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 @@ -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 diff --git a/config/fake.go b/config/fake.go index 18315c4..a23e2b1 100644 --- a/config/fake.go +++ b/config/fake.go @@ -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" } diff --git a/config/get.go b/config/get.go index 9b23a37..53e69a3 100644 --- a/config/get.go +++ b/config/get.go @@ -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() diff --git a/config/manager.go b/config/manager.go index b8f63e0..a524f81 100644 --- a/config/manager.go +++ b/config/manager.go @@ -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. diff --git a/constants/env.go b/constants/env.go index 0323e80..919e77e 100644 --- a/constants/env.go +++ b/constants/env.go @@ -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" diff --git a/controllers/topology/deployment.go b/controllers/topology/deployment.go index cd3df21..d68acc9 100644 --- a/controllers/topology/deployment.go +++ b/controllers/topology/deployment.go @@ -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, @@ -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, @@ -548,6 +553,10 @@ func (r *DeploymentReconciler) renderDeploymentContainerEnv( Name: clabernetesconstants.LauncherContainerlabVersion, Value: containerlabVersion, }, + { + Name: clabernetesconstants.LauncherContainerlabTimeout, + Value: containerlabTimeout, + }, } if ResolveGlobalVsTopologyBool( diff --git a/controllers/topology/test-fixtures/golden/deployment/render-deployment/containerlab-debug.json b/controllers/topology/test-fixtures/golden/deployment/render-deployment/containerlab-debug.json index 161ab53..984ce25 100755 --- a/controllers/topology/test-fixtures/golden/deployment/render-deployment/containerlab-debug.json +++ b/controllers/topology/test-fixtures/golden/deployment/render-deployment/containerlab-debug.json @@ -130,6 +130,9 @@ { "name": "LAUNCHER_CONTAINERLAB_VERSION" }, + { + "name": "LAUNCHER_CONTAINERLAB_TIMEOUT" + }, { "name": "LAUNCHER_CONTAINERLAB_DEBUG", "value": "true" diff --git a/controllers/topology/test-fixtures/golden/deployment/render-deployment/custom-clab-version.json b/controllers/topology/test-fixtures/golden/deployment/render-deployment/custom-clab-version.json index 6f6ddc8..07257bf 100755 --- a/controllers/topology/test-fixtures/golden/deployment/render-deployment/custom-clab-version.json +++ b/controllers/topology/test-fixtures/golden/deployment/render-deployment/custom-clab-version.json @@ -130,6 +130,9 @@ "name": "LAUNCHER_CONTAINERLAB_VERSION", "value": "0.51.1" }, + { + "name": "LAUNCHER_CONTAINERLAB_TIMEOUT" + }, { "name": "LAUNCHER_PRIVILEGED", "value": "true" diff --git a/controllers/topology/test-fixtures/golden/deployment/render-deployment/docker-daemon.json b/controllers/topology/test-fixtures/golden/deployment/render-deployment/docker-daemon.json index 02f922e..19dfcaa 100755 --- a/controllers/topology/test-fixtures/golden/deployment/render-deployment/docker-daemon.json +++ b/controllers/topology/test-fixtures/golden/deployment/render-deployment/docker-daemon.json @@ -137,6 +137,9 @@ { "name": "LAUNCHER_CONTAINERLAB_VERSION" }, + { + "name": "LAUNCHER_CONTAINERLAB_TIMEOUT" + }, { "name": "LAUNCHER_PRIVILEGED", "value": "true" diff --git a/controllers/topology/test-fixtures/golden/deployment/render-deployment/insecure-registries.json b/controllers/topology/test-fixtures/golden/deployment/render-deployment/insecure-registries.json index 04a67f8..edfc1d3 100755 --- a/controllers/topology/test-fixtures/golden/deployment/render-deployment/insecure-registries.json +++ b/controllers/topology/test-fixtures/golden/deployment/render-deployment/insecure-registries.json @@ -130,6 +130,9 @@ { "name": "LAUNCHER_CONTAINERLAB_VERSION" }, + { + "name": "LAUNCHER_CONTAINERLAB_TIMEOUT" + }, { "name": "LAUNCHER_INSECURE_REGISTRIES", "value": "1.2.3.4,potato.com" diff --git a/controllers/topology/test-fixtures/golden/deployment/render-deployment/launcher-log-level.json b/controllers/topology/test-fixtures/golden/deployment/render-deployment/launcher-log-level.json index 67e5e34..92f7c23 100755 --- a/controllers/topology/test-fixtures/golden/deployment/render-deployment/launcher-log-level.json +++ b/controllers/topology/test-fixtures/golden/deployment/render-deployment/launcher-log-level.json @@ -130,6 +130,9 @@ { "name": "LAUNCHER_CONTAINERLAB_VERSION" }, + { + "name": "LAUNCHER_CONTAINERLAB_TIMEOUT" + }, { "name": "LAUNCHER_PRIVILEGED", "value": "true" diff --git a/controllers/topology/test-fixtures/golden/deployment/render-deployment/not-privileged-launcher.json b/controllers/topology/test-fixtures/golden/deployment/render-deployment/not-privileged-launcher.json index 5c81426..fdebe18 100755 --- a/controllers/topology/test-fixtures/golden/deployment/render-deployment/not-privileged-launcher.json +++ b/controllers/topology/test-fixtures/golden/deployment/render-deployment/not-privileged-launcher.json @@ -156,6 +156,9 @@ }, { "name": "LAUNCHER_CONTAINERLAB_VERSION" + }, + { + "name": "LAUNCHER_CONTAINERLAB_TIMEOUT" } ], "resources": {}, diff --git a/controllers/topology/test-fixtures/golden/deployment/render-deployment/remove-prefix.json b/controllers/topology/test-fixtures/golden/deployment/render-deployment/remove-prefix.json index ca12fda..d160b00 100755 --- a/controllers/topology/test-fixtures/golden/deployment/render-deployment/remove-prefix.json +++ b/controllers/topology/test-fixtures/golden/deployment/render-deployment/remove-prefix.json @@ -130,6 +130,9 @@ { "name": "LAUNCHER_CONTAINERLAB_VERSION" }, + { + "name": "LAUNCHER_CONTAINERLAB_TIMEOUT" + }, { "name": "LAUNCHER_PRIVILEGED", "value": "true" diff --git a/controllers/topology/test-fixtures/golden/deployment/render-deployment/scheduling.json b/controllers/topology/test-fixtures/golden/deployment/render-deployment/scheduling.json index 1080116..59a6503 100755 --- a/controllers/topology/test-fixtures/golden/deployment/render-deployment/scheduling.json +++ b/controllers/topology/test-fixtures/golden/deployment/render-deployment/scheduling.json @@ -130,6 +130,9 @@ { "name": "LAUNCHER_CONTAINERLAB_VERSION" }, + { + "name": "LAUNCHER_CONTAINERLAB_TIMEOUT" + }, { "name": "LAUNCHER_PRIVILEGED", "value": "true" diff --git a/controllers/topology/test-fixtures/golden/deployment/render-deployment/simple.json b/controllers/topology/test-fixtures/golden/deployment/render-deployment/simple.json index 3a63ac0..1a90325 100755 --- a/controllers/topology/test-fixtures/golden/deployment/render-deployment/simple.json +++ b/controllers/topology/test-fixtures/golden/deployment/render-deployment/simple.json @@ -130,6 +130,9 @@ { "name": "LAUNCHER_CONTAINERLAB_VERSION" }, + { + "name": "LAUNCHER_CONTAINERLAB_TIMEOUT" + }, { "name": "LAUNCHER_PRIVILEGED", "value": "true" diff --git a/e2e/clabverter/test-fixtures/golden/10-topology.clabverter-basic.yaml b/e2e/clabverter/test-fixtures/golden/10-topology.clabverter-basic.yaml index d242207..c348b89 100755 --- a/e2e/clabverter/test-fixtures/golden/10-topology.clabverter-basic.yaml +++ b/e2e/clabverter/test-fixtures/golden/10-topology.clabverter-basic.yaml @@ -23,6 +23,7 @@ spec: links: - endpoints: ["srl1:e1-1", "srl2:e1-1"] deployment: + containerlabTimeout: "" persistence: enabled: false scheduling: {} diff --git a/e2e/topology/basic/test-fixtures/golden/10-topology.topology-basic.yaml b/e2e/topology/basic/test-fixtures/golden/10-topology.topology-basic.yaml index 36896c9..92145b0 100755 --- a/e2e/topology/basic/test-fixtures/golden/10-topology.topology-basic.yaml +++ b/e2e/topology/basic/test-fixtures/golden/10-topology.topology-basic.yaml @@ -16,6 +16,7 @@ spec: kind: srl image: ghcr.io/nokia/srlinux deployment: + containerlabTimeout: "" persistence: enabled: false scheduling: {} diff --git a/generated/openapi/openapi_generated.go b/generated/openapi/openapi_generated.go index 1813131..1347276 100644 --- a/generated/openapi/openapi_generated.go +++ b/generated/openapi/openapi_generated.go @@ -234,6 +234,14 @@ func schema_srl_labs_clabernetes_apis_v1alpha1_ConfigDeployment( Format: "", }, }, + "containerlabTimeout": { + SchemaProps: spec.SchemaProps{ + Description: "ContainerlabTimeout sets the `--timeout` flag when invoking containerlab in the launcher pods.", + Default: "", + Type: []string{"string"}, + Format: "", + }, + }, "containerlabVersion": { SchemaProps: spec.SchemaProps{ Description: "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 careful! You never \"need\" to this as the publicly available launcher image will always be built with a (reasonably) up to date containerlab version, this setting exists in case you want to pin back to an older version for some reason or you want to be bleeding edge with some new feature (but do note that just because it exists in containerlab doesnt *necessarily* mean it will be auto-working in clabernetes!", @@ -781,6 +789,14 @@ func schema_srl_labs_clabernetes_apis_v1alpha1_Deployment( Format: "", }, }, + "containerlabTimeout": { + SchemaProps: spec.SchemaProps{ + Description: "ContainerlabTimeout sets the `--timeout` flag when invoking containerlab in the launcher pods.", + Default: "", + Type: []string{"string"}, + Format: "", + }, + }, "containerlabVersion": { SchemaProps: spec.SchemaProps{ Description: "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 careful! You never \"need\" to this as the publicly available launcher image will always be built with a (reasonably) up to date containerlab version, this setting exists in case you want to pin back to an older version for some reason or you want to be bleeding edge with some new feature (but do note that just because it exists in containerlab doesnt *necessarily* mean it will be auto-working in clabernetes!", diff --git a/launcher/containerlab.go b/launcher/containerlab.go index 4928318..36cb725 100644 --- a/launcher/containerlab.go +++ b/launcher/containerlab.go @@ -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