Skip to content

Commit 88b58e7

Browse files
authored
Merge pull request #22 from srl-labs/cfg-via-temp-dir
added startup-config provisioning via a temp dir
2 parents 938f6b9 + 08fcfa6 commit 88b58e7

File tree

5 files changed

+43
-14
lines changed

5 files changed

+43
-14
lines changed

README.md

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ This is a k8s controller for running and managing SR Linux nodes launched from [
44

55
## Install
66

7-
To install the latest version of this controller on a cluster referenced in `~/.kube/config` issue the following command:
7+
To install the latest version of this controller on a cluster referenced in `~/.kube/config`, issue the following command:
88

99
```bash
1010
# latest version
@@ -54,7 +54,7 @@ kubectl delete -k https://github.com/srl-labs/srl-controller/config/default
5454

5555
To run this controller in a test cluster deployed with [`kne`](https://github.com/openconfig/kne) and [`kind`](https://kind.sigs.k8s.io/) follow the steps outlined in the [KNE repository](https://github.com/openconfig/kne/tree/main/docs).
5656

57-
Once the kne+kind cluster is created, a [demo topology with two SR Linux nodes](https://github.com/openconfig/kne/blob/db5fe5be01a1b6b65bd79e740e2c819c5aeb50b0/examples/srlinux/2node-srl-with-config.pbtxt) may be deployed as follows:
57+
Once the kne+kind cluster is created and the `srl-controller` is installed onto it, a [demo topology with two SR Linux nodes](https://github.com/openconfig/kne/blob/db5fe5be01a1b6b65bd79e740e2c819c5aeb50b0/examples/srlinux/2node-srl-with-config.pbtxt) can be deployed as follows:
5858

5959
```bash
6060
kne create examples/srlinux/2node-srl-with-config.pbtxt
@@ -73,12 +73,17 @@ To connect with SSH to the `r1` node, use `ssh [email protected]` command.
7373

7474
### Loading images to kind cluster
7575

76-
[Public SR Linux container image](https://github.com/nokia/srlinux-container-image) will be pulled by kind automatically, if Internet access is present. Images which are not available publicy can be uploaded to kind manually:
76+
[Public SR Linux container image](https://github.com/nokia/srlinux-container-image) will be pulled by kind automatically if Internet access is present. Images which are not available publicy can be uploaded to kind manually:
7777

7878
```bash
7979
# default kne kind cluster name is `kne`
8080
# which is the last argument in the command
81+
82+
# load locally available container image
8183
kind load docker-image srlinux:0.0.0-38566 --name kne
84+
85+
# load publicly available container image
86+
kind load docker-image ghcr.io/nokia/srlinux:22.6.4 --name kne
8287
```
8388

8489
## Using license files
@@ -112,7 +117,7 @@ This repo contains a clientset for API access to the `Srlinux` custom resource.
112117

113118
## Building `srl-controller` container image
114119

115-
To build `srl-controller` container image execute:
120+
To build `srl-controller` container image, execute:
116121

117122
```bash
118123
# don't forget to set the correct tag
@@ -129,3 +134,23 @@ Finally, upload the container image to the registry:
129134
```bash
130135
docker push ghcr.io/srl-labs/srl-controller:${tag}
131136
```
137+
138+
## Developers guide
139+
140+
Developers should deploy the controller onto a cluster from the source code. Ensure that the `srl-controller` is [uninstalled](#uninstall) from the cluster before proceeding.
141+
142+
Install the Srlinux CRDs onto the cluster
143+
144+
```
145+
make install
146+
```
147+
148+
To build and run the controller from the source code:
149+
150+
```
151+
make run
152+
```
153+
154+
Controller's log printed to stdout/stderr. It is possible to deploy topologies with `kne create` now.
155+
156+
Make changes to the controller code-base, and re-run `make run` to see the changes in effect.

config/manager/kustomization.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@ kind: Kustomization
1717
images:
1818
- name: controller
1919
newName: ghcr.io/srl-labs/srl-controller
20-
newTag: 0.4.3
20+
newTag: 0.4.4

controllers/pod.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -170,24 +170,25 @@ func createVolumes(s *typesv1a1.Srlinux) []corev1.Volume {
170170
}
171171

172172
// handleStartupConfig creates volume mounts and volumes for srlinux pod
173-
// if the config file was provided in the spec.
173+
// if the (startup) config file was provided in the spec.
174+
// Volume mounts happens in the /tmp/startup-config directory and not in the /etc/opt/srlinux
175+
// because we need to support renaming operations on config.json, and bind mount paths are not allowing this.
176+
// Hence the temp location, from which the config file is then copied to /etc/opt/srlinux by the kne-entrypoint.sh.
174177
func handleStartupConfig(s *typesv1a1.Srlinux, pod *corev1.Pod, log logr.Logger) {
175178
// initialize config path and config file variables
176179
cfgPath := defaultConfigPath
177180
if p := s.Spec.GetConfig().ConfigPath; p != "" {
178181
cfgPath = p
179182
}
180183

181-
cfgFile := s.Spec.GetConfig().ConfigFile
182-
183184
// only create startup config mounts if the config data was set in kne
184185
if s.Spec.Config.ConfigDataPresent {
185186
log.Info(
186187
"Adding volume for startup config to pod spec",
187188
"volume.name",
188189
"startup-config-volume",
189190
"mount.path",
190-
cfgPath+"/"+cfgFile,
191+
cfgPath,
191192
)
192193

193194
pod.Spec.Volumes = append(pod.Spec.Volumes, corev1.Volume{
@@ -205,9 +206,8 @@ func handleStartupConfig(s *typesv1a1.Srlinux, pod *corev1.Pod, log logr.Logger)
205206
pod.Spec.Containers[0].VolumeMounts,
206207
corev1.VolumeMount{
207208
Name: "startup-config-volume",
208-
MountPath: cfgPath + "/" + cfgFile,
209-
SubPath: cfgFile,
210-
ReadOnly: true,
209+
MountPath: cfgPath,
210+
ReadOnly: false,
211211
},
212212
)
213213
}

controllers/srlinux_controller.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ const (
4242
entrypointVolMntSubPath = "kne-entrypoint.sh"
4343
entrypointCfgMapName = "srlinux-kne-entrypoint"
4444

45-
// default path to a startup config file
45+
// default path to a startup config directory
4646
// the default for config file name resides within kne.
47-
defaultConfigPath = "/etc/opt/srlinux"
47+
defaultConfigPath = "/tmp/startup-config"
4848

4949
fileMode777 = 0o777
5050

manifests/variants/kne-entrypoint.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,8 @@ data:
1515
1616
sudo bash /tmp/topomac/topomac.sh
1717
echo "topomac.sh" script finished
18+
19+
# copy potentially provided startup config files
20+
sudo cp -L /tmp/startup-config/* /etc/opt/srlinux/
21+
1822
exec /entrypoint.sh "$@"

0 commit comments

Comments
 (0)