Skip to content

Commit 606f2b9

Browse files
authored
Update deps and init container config (#45)
* update controller runtime and direct deps * update controller gen tools * move api helper functions to _helpers * update ci deps * set version golangci * update more deps * added status subresource to the fake client kubernetes-sigs/controller-runtime#2072 https://github.com/kubernetes-sigs/controller-runtime/releases/tag/v0.14.0 * fix lint issues * fix versions in the e2e test * change default cpu and mem constraints * added custom init image support * added init image unit test * added e2e test with custom image * update dockerfile for Go 1.24.9 * added custom image to the e2e matrix * bump version * tune e2e tests * added more logging for e2e tests * fix unit for cpu requests and lower for CI * bumping versions in the release pipeline
1 parent b58bd91 commit 606f2b9

26 files changed

+645
-548
lines changed

.github/workflows/cicd.yml

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,55 +14,55 @@ on:
1414
workflow_dispatch:
1515

1616
env:
17-
GOVER: 1.20.2
17+
GOVER: 1.24.9
1818
CGO_ENABLED: 0
1919

2020
jobs:
2121
test:
22-
runs-on: ubuntu-22.04
22+
runs-on: ubuntu-24.04
2323
steps:
24-
- uses: actions/checkout@v3
25-
- uses: actions/setup-go@v4
24+
- uses: actions/checkout@v6
25+
- uses: actions/setup-go@v6
2626
with:
2727
go-version: ${{ env.GOVER }}
2828
- name: Test
2929
run: make test
3030
- name: Upload coverage to Codecov
31-
uses: codecov/codecov-action@v3
31+
uses: codecov/codecov-action@v5
3232

3333
golang-ci-lint:
34-
runs-on: ubuntu-22.04
34+
runs-on: ubuntu-24.04
3535
steps:
3636
- name: Checkout
37-
uses: actions/checkout@v3
37+
uses: actions/checkout@v6
3838
with:
3939
fetch-depth: 0
40-
- uses: actions/setup-go@v4
40+
- uses: actions/setup-go@v6
4141
with:
4242
go-version: ${{ env.GOVER }}
4343
- name: golangci-lint
44-
uses: golangci/golangci-lint-action@v3
44+
uses: golangci/golangci-lint-action@v9
4545
with:
46-
args: --config=./.github/workflows/linters/.golangci.yml
47-
version: "v1.51.2"
46+
# args: --config=./.github/workflows/linters/.golangci.yml
47+
version: "v2.1"
4848

4949
release:
50-
runs-on: ubuntu-22.04
50+
runs-on: ubuntu-24.04
5151
if: startsWith(github.ref, 'refs/tags/v')
5252
needs:
5353
- golang-ci-lint
5454
- test
5555
steps:
56-
- uses: actions/checkout@v3
57-
- uses: actions/setup-go@v4
56+
- uses: actions/checkout@v6
57+
- uses: actions/setup-go@v6
5858
with:
5959
go-version: ${{ env.GOVER }}
6060

6161
- name: Build container
6262
run: "IMG=ghcr.io/srl-labs/srl-controller:$GITHUB_REF_NAME make only-docker-build"
6363

6464
- name: Login to GitHub Container Registry
65-
uses: docker/login-action@v2
65+
uses: docker/login-action@v3
6666
with:
6767
registry: ghcr.io
6868
username: ${{ github.actor }}
@@ -75,6 +75,6 @@ jobs:
7575
docker push ghcr.io/srl-labs/srl-controller:latest
7676
7777
- name: Create GH release
78-
uses: softprops/action-gh-release@v1
78+
uses: softprops/action-gh-release@v2
7979
with:
8080
generate_release_notes: true

.github/workflows/e2e.yml

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,21 @@ name: E2E
66
kne_ref:
77
description: "openconfig/kne reference (tag, commit, branch)"
88
type: string
9-
default: v0.1.9
9+
default: v0.3.1
1010
required: true
1111
kind_version:
1212
description: "KinD version"
1313
type: string
1414
required: true
15-
default: v0.17.0
15+
default: v0.24.0
1616

1717
env:
18-
GOVER: 1.20.2
18+
GOVER: 1.24.9
1919

2020
jobs:
2121
e2e:
2222
name: End-to-end test
23-
runs-on: ubuntu-latest
23+
runs-on: ubuntu-24.04
2424
strategy:
2525
fail-fast: false
2626
matrix:
@@ -29,22 +29,23 @@ jobs:
2929
"TestSrlinuxReconciler_BareSrlinuxCR",
3030
"TestSrlinuxReconciler_WithJSONStartupConfig",
3131
"TestSrlinuxReconciler_WithCLIStartupConfig",
32+
"TestSrlinuxReconciler_WithCustomInitImage",
3233
]
3334

3435
steps:
3536
- name: Set env vars
3637
run: |
3738
echo "KNE_REF=${{ inputs.kne_ref }}" >> $GITHUB_ENV
3839
39-
- uses: actions/checkout@v3
40+
- uses: actions/checkout@v6
4041

4142
- name: Set up Go
42-
uses: actions/setup-go@v4
43+
uses: actions/setup-go@v6
4344
with:
4445
go-version: ${{ env.GOVER }}
4546

4647
- name: Install kind
47-
uses: engineerd/setup-kind@v0.5.0
48+
uses: engineerd/setup-kind@v0.6.2
4849
with:
4950
name: srl-test # cluster name
5051
version: ${{ inputs.kind_version }}
@@ -54,6 +55,6 @@ jobs:
5455
run: make prepare-e2e-env
5556

5657
- name: Run e2e tests
57-
# this test ensures that srl-controller (built from referenced source) can be succesfully installed on a KNE cluster
58+
# this test ensures that srl-controller (built from referenced source) can be successfully installed on a KNE cluster
5859
# for a using specified versions of KNE/KinD
5960
run: E2E_TEST_NAME=${{ matrix.test }} make test-e2e

.github/workflows/linters/.golangci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
run:
66
# running w/ 1.17 because we dont actually need/use 1.18 things and 1.18 breaks some linters.
7-
go: "1.17"
7+
go: "1.24.9"
88
timeout: 5m
99
skip-dirs:
1010
- private

.mk/e2e.mk

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
# KNE_REF is a git reference to use for KNE. It can be a branch, tag, or commit hash.
2-
KNE_REF ?= v0.1.9
2+
KNE_REF ?= v0.3.1
33
KNE_REPO := https://github.com/openconfig/kne.git
44
KNE_TEMP_DIR := /tmp/.srlcontroller-tests/kne
55
KNE_TEST_DEPLOYMENT_FILE := ${KNE_TEMP_DIR}/deploy/kne/kind-bridge-no-controllers.yaml
66
KIND_CLUSTER_NAME ?= srl-test
7-
SRL_IMAGE ?= ghcr.io/nokia/srlinux:latest
7+
SRL_IMAGE ?= ghcr.io/nokia/srlinux:25.10
88

99
.PHONY: install-kne
1010
install-kne: ## Install KNE

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# SPDX-License-Identifier: BSD-3-Clause
44

55
# Build the manager binary
6-
FROM golang:1.20 as builder
6+
FROM golang:1.24.9 as builder
77
ARG TARGETOS
88
ARG TARGETARCH
99

Makefile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ include .mk/e2e.mk
44
# Image URL to use all building/pushing image targets
55
IMG ?= controller:latest
66
# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
7-
ENVTEST_K8S_VERSION = 1.25.0
7+
ENVTEST_K8S_VERSION = 1.31.0
88

99
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
1010
ifeq (,$(shell go env GOBIN))
@@ -142,8 +142,8 @@ CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen
142142
ENVTEST ?= $(LOCALBIN)/setup-envtest
143143

144144
## Tool Versions
145-
KUSTOMIZE_VERSION ?= v3.8.7
146-
CONTROLLER_TOOLS_VERSION ?= v0.10.0
145+
KUSTOMIZE_VERSION ?= v5.4.2
146+
CONTROLLER_TOOLS_VERSION ?= v0.16.5
147147

148148
KUSTOMIZE_INSTALL_SCRIPT ?= "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh"
149149
.PHONY: kustomize
@@ -164,4 +164,4 @@ $(CONTROLLER_GEN): $(LOCALBIN)
164164
.PHONY: envtest
165165
envtest: $(ENVTEST) ## Download envtest-setup locally if necessary.
166166
$(ENVTEST): $(LOCALBIN)
167-
test -s $(LOCALBIN)/setup-envtest || GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-runtime/tools/setup-envtest@release-0.17
167+
test -s $(LOCALBIN)/setup-envtest || GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-runtime/tools/setup-envtest@release-0.19

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ Available statuses:
8484

8585
- `STATUS`: `Running` when the underlying pod is running. The status is copied from the pod status.
8686
- `READY`: `true` when the SR Linux node is ready to accept configuration. The status is `true` when SR Linux management servers is ready to accept connections and configurations.
87-
- `CONFIG`: `loaded` when the startup-configuration is succesfully applied. The status is `failed` when errors occured during startup-configuration load.
87+
- `CONFIG`: `loaded` when the startup-configuration is successfully applied. The status is `failed` when errors occurred during startup-configuration load.
8888

8989
The services will be exposed via MetalLB and can be queried as:
9090

@@ -162,7 +162,7 @@ docker tag ghcr.io/srl-labs/srl-controller:${tag} ghcr.io/srl-labs/srl-controlle
162162
docker push ghcr.io/srl-labs/srl-controller:latest
163163
```
164164

165-
Note, update the SR Linux manifest in the [KNE repo](https://github.com/openconfig/kne/) to use the new version of the controller. To generate the manifest, run:
165+
Note, update the SR Linux manifest in the [KNE repo](https://github.com/openconfig/kne/tree/main/manifests/controllers/srlinux) to use the new version of the controller. To generate the manifest, run:
166166

167167
```bash
168168
kustomize build config/default

api/v1/srl_version.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package v1
66

77
import (
88
"regexp"
9+
"slices"
910
"strings"
1011
)
1112

@@ -21,10 +22,8 @@ type SrlVersion struct {
2122
func parseVersionString(s string) *SrlVersion {
2223
// Check if the version string is an engineering build with major = 0
2324
engineeringVersions := []string{"", "latest", "ga"}
24-
for _, ver := range engineeringVersions {
25-
if ver == strings.ToLower(s) {
26-
return &SrlVersion{"0", "", "", "", ""}
27-
}
25+
if slices.Contains(engineeringVersions, strings.ToLower(s)) {
26+
return &SrlVersion{"0", "", "", "", ""}
2827
}
2928

3029
// https://regex101.com/r/eWS6Ms/3

api/v1/srlinux_helpers.go

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
/*
2+
Copyright (c) 2021 Nokia. All rights reserved.
3+
4+
5+
Redistribution and use in source and binary forms, with or without
6+
modification, are permitted provided that the following conditions are met:
7+
8+
1. Redistributions of source code must retain the above copyright notice, this
9+
list of conditions and the following disclaimer.
10+
11+
2. Redistributions in binary form must reproduce the above copyright notice,
12+
this list of conditions and the following disclaimer in the documentation
13+
and/or other materials provided with the distribution.
14+
15+
3. Neither the name of the copyright holder nor the names of its
16+
contributors may be used to endorse or promote products derived from
17+
this software without specific prior written permission.
18+
19+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
23+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29+
*/
30+
31+
package v1
32+
33+
import (
34+
"context"
35+
"fmt"
36+
"strings"
37+
38+
corev1 "k8s.io/api/core/v1"
39+
)
40+
41+
// key value for a combined license file stored in a secret.
42+
const allSecretKey = "all.key"
43+
44+
// GetConfig gets config from srlinux spec.
45+
func (s *SrlinuxSpec) GetConfig() *NodeConfig {
46+
if s.Config != nil {
47+
return s.Config
48+
}
49+
50+
return &NodeConfig{}
51+
}
52+
53+
// GetConstraints gets constraints from srlinux spec,
54+
// default constraints are returned if none are present in the spec.
55+
func (s *SrlinuxSpec) GetConstraints() map[string]string {
56+
if s.Constraints != nil {
57+
return s.Constraints
58+
}
59+
60+
return defaultConstraints
61+
}
62+
63+
// GetModel gets srlinux model (aka variant) from srlinux spec,
64+
// default srlinux variant is returned if none present in the spec.
65+
func (s *SrlinuxSpec) GetModel() string {
66+
if s.Model != "" {
67+
return s.Model
68+
}
69+
70+
return defaultSrlinuxVariant
71+
}
72+
73+
// GetImage returns the srlinux container image name that is used in pod spec
74+
// if Config.Image is provided it takes precedence over all other option
75+
// if not, the Spec.Version is used as a tag for public container image ghcr.io/nokia/srlinux.
76+
func (s *SrlinuxSpec) GetImage() string {
77+
img := defaultSrLinuxImageName
78+
79+
if s.GetConfig().Image != "" {
80+
img = s.GetConfig().Image
81+
}
82+
83+
// when image is not defined, but version is
84+
// the version is used as a tag for a default image repo
85+
if s.GetConfig().Image == "" && s.Version != "" {
86+
img = img + ":" + s.Version
87+
}
88+
89+
return img
90+
}
91+
92+
// GetInitImage gets init container image from the srlinux spec,
93+
// default init container image is returned if none present in the spec.
94+
func (s *SrlinuxSpec) GetInitImage() string {
95+
if s.GetConfig().InitImage != "" {
96+
return s.GetConfig().InitImage
97+
}
98+
99+
return defaultSrlinuxInitContainerImage
100+
}
101+
102+
// GetImageVersion finds an srlinux image version by looking at the Image field of the spec
103+
// as well as at Version field.
104+
// When Version field is set it is returned.
105+
// In other cases, Image string is evaluated and it's tag substring is parsed.
106+
// If no tag is present, or tag is latest, the 0.0 version is assumed to be in use.
107+
func (s *SrlinuxSpec) GetImageVersion() *SrlVersion {
108+
if s.Version != "" {
109+
return parseVersionString(s.Version)
110+
}
111+
112+
var tag string
113+
114+
split := strings.Split(s.GetImage(), ":")
115+
if len(split) == 2 { //nolint:gomnd
116+
tag = split[1]
117+
}
118+
119+
return parseVersionString(tag)
120+
}
121+
122+
// InitLicenseKey sets the Srlinux.LicenseKey to a value of a key
123+
// that matches MAJOR-MINOR.key of a passed secret.
124+
// Where MAJOR-MINOR is retrieved from the image version.
125+
// If such key doesn't exist, it checks if a wildcard `all.key` is found in that secret,
126+
// if nothing found, LicenseKey stays empty, which denotes that no license was found for Srlinux.
127+
func (s *Srlinux) InitLicenseKey(
128+
_ context.Context,
129+
secret *corev1.Secret,
130+
version *SrlVersion,
131+
) {
132+
if secret == nil {
133+
return
134+
}
135+
136+
versionSecretKey := fmt.Sprintf("%s-%s.key", version.Major, version.Minor)
137+
if _, ok := secret.Data[versionSecretKey]; ok {
138+
s.LicenseKey = versionSecretKey
139+
140+
return
141+
}
142+
143+
if _, ok := secret.Data[allSecretKey]; ok {
144+
s.LicenseKey = allSecretKey
145+
146+
return
147+
}
148+
}

0 commit comments

Comments
 (0)