Skip to content

Commit

Permalink
Merge pull request #146 from srl-labs/feat/docker-config-from-secret
Browse files Browse the repository at this point in the history
feat: docker config for launcher user
  • Loading branch information
carlmontanari authored May 10, 2024
2 parents 1ce5938 + 6997be1 commit 4a26818
Show file tree
Hide file tree
Showing 13 changed files with 347 additions and 1 deletion.
7 changes: 7 additions & 0 deletions apis/v1alpha1/configspec.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,4 +115,11 @@ type ConfigImagePull struct {
// /etc/docker and docker will be expecting the config at /etc/docker/daemon.json.
// +optional
DockerDaemonConfig string `json:"dockerDaemonConfig,omitempty"`
// DockerConfig allows for setting the docker user (for root) config for all launchers in this
// topology. The secret *must be present in the namespace of this topology*. The secret *must*
// contain a key "config.json" -- as this secret will be mounted to /root/.docker/config.json
// and as such wil be utilized when doing docker-y things -- this means you can put auth things
// in here in the event your cluster doesn't support the preferred image pull through option.
// +optional
DockerConfig string `json:"dockerConfig,omitempty"`
}
7 changes: 7 additions & 0 deletions apis/v1alpha1/topologyspec.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,4 +223,11 @@ type ImagePull struct {
// be expecting the config at /etc/docker/daemon.json.
// +optional
DockerDaemonConfig string `json:"dockerDaemonConfig,omitempty"`
// DockerConfig allows for setting the docker user (for root) config for all launchers in this
// topology. The secret *must be present in the namespace of this topology*. The secret *must*
// contain a key "config.json" -- as this secret will be mounted to /root/.docker/config.json
// and as such wil be utilized when doing docker-y things -- this means you can put auth things
// in here in the event your cluster doesn't support the preferred image pull through option.
// +optional
DockerConfig string `json:"dockerConfig,omitempty"`
}
8 changes: 8 additions & 0 deletions assets/crd/clabernetes.containerlab.dev_configs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,14 @@ spec:
now, in the future maybe crio support will be added.
pattern: (.*containerd\.sock)
type: string
dockerConfig:
description: |-
DockerConfig allows for setting the docker user (for root) config for all launchers in this
topology. The secret *must be present in the namespace of this topology*. The secret *must*
contain a key "config.json" -- as this secret will be mounted to /root/.docker/config.json
and as such wil be utilized when doing docker-y things -- this means you can put auth things
in here in the event your cluster doesn't support the preferred image pull through option.
type: string
dockerDaemonConfig:
description: |-
DockerDaemonConfig allows for setting a default docker daemon config for launcher pods
Expand Down
8 changes: 8 additions & 0 deletions assets/crd/clabernetes.containerlab.dev_topologies.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,14 @@ spec:
ImagePull holds configurations relevant to how clabernetes launcher pods handle pulling
images.
properties:
dockerConfig:
description: |-
DockerConfig allows for setting the docker user (for root) config for all launchers in this
topology. The secret *must be present in the namespace of this topology*. The secret *must*
contain a key "config.json" -- as this secret will be mounted to /root/.docker/config.json
and as such wil be utilized when doing docker-y things -- this means you can put auth things
in here in the event your cluster doesn't support the preferred image pull through option.
type: string
dockerDaemonConfig:
description: |-
DockerDaemonConfig allows for setting the docker daemon config for all launchers in this
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,14 @@ spec:
now, in the future maybe crio support will be added.
pattern: (.*containerd\.sock)
type: string
dockerConfig:
description: |-
DockerConfig allows for setting the docker user (for root) config for all launchers in this
topology. The secret *must be present in the namespace of this topology*. The secret *must*
contain a key "config.json" -- as this secret will be mounted to /root/.docker/config.json
and as such wil be utilized when doing docker-y things -- this means you can put auth things
in here in the event your cluster doesn't support the preferred image pull through option.
type: string
dockerDaemonConfig:
description: |-
DockerDaemonConfig allows for setting a default docker daemon config for launcher pods
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,14 @@ spec:
ImagePull holds configurations relevant to how clabernetes launcher pods handle pulling
images.
properties:
dockerConfig:
description: |-
DockerConfig allows for setting the docker user (for root) config for all launchers in this
topology. The secret *must be present in the namespace of this topology*. The secret *must*
contain a key "config.json" -- as this secret will be mounted to /root/.docker/config.json
and as such wil be utilized when doing docker-y things -- this means you can put auth things
in here in the event your cluster doesn't support the preferred image pull through option.
type: string
dockerDaemonConfig:
description: |-
DockerDaemonConfig allows for setting the docker daemon config for all launchers in this
Expand Down
4 changes: 4 additions & 0 deletions config/fake.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ func (f fakeManager) GetDockerDaemonConfig() string {
return ""
}

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

func (f fakeManager) GetLauncherImagePullPolicy() string {
return clabernetesconstants.KubernetesImagePullIfNotPresent
}
Expand Down
7 changes: 7 additions & 0 deletions config/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,13 @@ func (m *manager) GetDockerDaemonConfig() string {
return m.config.ImagePull.DockerDaemonConfig
}

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

return m.config.ImagePull.DockerConfig
}

func (m *manager) GetLauncherImage() string {
m.lock.RLock()
defer m.lock.RUnlock()
Expand Down
6 changes: 5 additions & 1 deletion config/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,12 @@ type Manager interface {
GetImagePullCriSockOverride() string
// GetImagePullCriKindOverride returns the cri kind override.
GetImagePullCriKindOverride() string
// GetDockerDaemonConfig returns the secret name to mount in /etc/docker.
// GetDockerDaemonConfig returns the secret name to mount in /etc/docker -- the secret *must*
// have a key "daemon.json" so the final mounted file is /etc/docker/daemon.json.
GetDockerDaemonConfig() string
// GetDockerConfig returns the secret name to mount in /root/.docker/ -- the secret *must* have
// a key "config.json" so the final mounted file is /root/.docker/config.json.
GetDockerConfig() string
// GetLauncherImage returns the global default launcher image.
GetLauncherImage() string
// GetLauncherImagePullPolicy returns the global default launcher image pull policy.
Expand Down
31 changes: 31 additions & 0 deletions controllers/topology/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,37 @@ func (r *DeploymentReconciler) renderDeploymentVolumes( //nolint:funlen
)
}

dockerConfigSecret := owningTopology.Spec.ImagePull.DockerConfig
if dockerConfigSecret == "" {
dockerConfigSecret = r.configManagerGetter().GetDockerConfig()
}

if dockerConfigSecret != "" {
volumes = append(
volumes,
k8scorev1.Volume{
Name: "docker-config",
VolumeSource: k8scorev1.VolumeSource{
Secret: &k8scorev1.SecretVolumeSource{
SecretName: dockerConfigSecret,
DefaultMode: clabernetesutil.ToPointer(
int32(clabernetesconstants.PermissionsEveryoneReadWriteOwnerExecute),
),
},
},
},
)

volumeMountsFromCommonSpec = append(
volumeMountsFromCommonSpec,
k8scorev1.VolumeMount{
Name: "docker-config",
ReadOnly: true,
MountPath: "/root/.docker",
},
)
}

volumesFromConfigMaps := make([]clabernetesapisv1alpha1.FileFromConfigMap, 0)

volumesFromConfigMaps = append(
Expand Down
46 changes: 46 additions & 0 deletions controllers/topology/deployment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,52 @@ func TestRenderDeployment(t *testing.T) {
},
nodeName: "srl1",
},
{
name: "docker-config",
owningTopology: &clabernetesapisv1alpha1.Topology{
ObjectMeta: metav1.ObjectMeta{
Name: "render-deployment-test",
Namespace: "clabernetes",
},
Spec: clabernetesapisv1alpha1.TopologySpec{
Connectivity: clabernetesconstants.ConnectivityVXLAN,
ImagePull: clabernetesapisv1alpha1.ImagePull{
DockerConfig: "sneakydockerconfig",
},
Definition: clabernetesapisv1alpha1.Definition{
Containerlab: `---
name: test
topology:
nodes:
srl1:
kind: srl
image: ghcr.io/nokia/srlinux
`,
},
},
},
clabernetesConfigs: map[string]*clabernetesutilcontainerlab.Config{
"srl1": {
Name: "srl1",
Prefix: clabernetesutil.ToPointer(""),
Topology: &clabernetesutilcontainerlab.Topology{
Defaults: &clabernetesutilcontainerlab.NodeDefinition{
Ports: []string{},
},
Kinds: nil,
Nodes: map[string]*clabernetesutilcontainerlab.NodeDefinition{
"srl1": {
Kind: "srl",
Image: "ghcr.io/nokia/srlinux",
},
},
Links: nil,
},
Debug: false,
},
},
nodeName: "srl1",
},
{
name: "scheduling",
owningTopology: &clabernetesapisv1alpha1.Topology{
Expand Down
Loading

0 comments on commit 4a26818

Please sign in to comment.