Skip to content
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
32 changes: 16 additions & 16 deletions .github/workflows/cicd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,55 +14,55 @@ on:
workflow_dispatch:

env:
GOVER: 1.20.2
GOVER: 1.24.9
CGO_ENABLED: 0

jobs:
test:
runs-on: ubuntu-22.04
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v4
- uses: actions/checkout@v6
- uses: actions/setup-go@v6
with:
go-version: ${{ env.GOVER }}
- name: Test
run: make test
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
uses: codecov/codecov-action@v5

golang-ci-lint:
runs-on: ubuntu-22.04
runs-on: ubuntu-24.04
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v6
with:
fetch-depth: 0
- uses: actions/setup-go@v4
- uses: actions/setup-go@v6
with:
go-version: ${{ env.GOVER }}
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
uses: golangci/golangci-lint-action@v9
with:
args: --config=./.github/workflows/linters/.golangci.yml
version: "v1.51.2"
# args: --config=./.github/workflows/linters/.golangci.yml
version: "v2.1"

release:
runs-on: ubuntu-22.04
runs-on: ubuntu-24.04
if: startsWith(github.ref, 'refs/tags/v')
needs:
- golang-ci-lint
- test
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v4
- uses: actions/checkout@v6
- uses: actions/setup-go@v6
with:
go-version: ${{ env.GOVER }}

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

- name: Login to GitHub Container Registry
uses: docker/login-action@v2
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
Expand All @@ -75,6 +75,6 @@ jobs:
docker push ghcr.io/srl-labs/srl-controller:latest

- name: Create GH release
uses: softprops/action-gh-release@v1
uses: softprops/action-gh-release@v2
with:
generate_release_notes: true
17 changes: 9 additions & 8 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,21 @@ name: E2E
kne_ref:
description: "openconfig/kne reference (tag, commit, branch)"
type: string
default: v0.1.9
default: v0.3.1
required: true
kind_version:
description: "KinD version"
type: string
required: true
default: v0.17.0
default: v0.24.0

env:
GOVER: 1.20.2
GOVER: 1.24.9

jobs:
e2e:
name: End-to-end test
runs-on: ubuntu-latest
runs-on: ubuntu-24.04
strategy:
fail-fast: false
matrix:
Expand All @@ -29,22 +29,23 @@ jobs:
"TestSrlinuxReconciler_BareSrlinuxCR",
"TestSrlinuxReconciler_WithJSONStartupConfig",
"TestSrlinuxReconciler_WithCLIStartupConfig",
"TestSrlinuxReconciler_WithCustomInitImage",
]

steps:
- name: Set env vars
run: |
echo "KNE_REF=${{ inputs.kne_ref }}" >> $GITHUB_ENV

- uses: actions/checkout@v3
- uses: actions/checkout@v6

- name: Set up Go
uses: actions/setup-go@v4
uses: actions/setup-go@v6
with:
go-version: ${{ env.GOVER }}

- name: Install kind
uses: engineerd/setup-kind@v0.5.0
uses: engineerd/setup-kind@v0.6.2
with:
name: srl-test # cluster name
version: ${{ inputs.kind_version }}
Expand All @@ -54,6 +55,6 @@ jobs:
run: make prepare-e2e-env

- name: Run e2e tests
# this test ensures that srl-controller (built from referenced source) can be succesfully installed on a KNE cluster
# this test ensures that srl-controller (built from referenced source) can be successfully installed on a KNE cluster
# for a using specified versions of KNE/KinD
run: E2E_TEST_NAME=${{ matrix.test }} make test-e2e
2 changes: 1 addition & 1 deletion .github/workflows/linters/.golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

run:
# running w/ 1.17 because we dont actually need/use 1.18 things and 1.18 breaks some linters.
go: "1.17"
go: "1.24.9"
timeout: 5m
skip-dirs:
- private
Expand Down
4 changes: 2 additions & 2 deletions .mk/e2e.mk
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# KNE_REF is a git reference to use for KNE. It can be a branch, tag, or commit hash.
KNE_REF ?= v0.1.9
KNE_REF ?= v0.3.1
KNE_REPO := https://github.com/openconfig/kne.git
KNE_TEMP_DIR := /tmp/.srlcontroller-tests/kne
KNE_TEST_DEPLOYMENT_FILE := ${KNE_TEMP_DIR}/deploy/kne/kind-bridge-no-controllers.yaml
KIND_CLUSTER_NAME ?= srl-test
SRL_IMAGE ?= ghcr.io/nokia/srlinux:latest
SRL_IMAGE ?= ghcr.io/nokia/srlinux:25.10

.PHONY: install-kne
install-kne: ## Install KNE
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# SPDX-License-Identifier: BSD-3-Clause

# Build the manager binary
FROM golang:1.20 as builder
FROM golang:1.24.9 as builder
ARG TARGETOS
ARG TARGETARCH

Expand Down
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ include .mk/e2e.mk
# Image URL to use all building/pushing image targets
IMG ?= controller:latest
# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
ENVTEST_K8S_VERSION = 1.25.0
ENVTEST_K8S_VERSION = 1.31.0

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

## Tool Versions
KUSTOMIZE_VERSION ?= v3.8.7
CONTROLLER_TOOLS_VERSION ?= v0.10.0
KUSTOMIZE_VERSION ?= v5.4.2
CONTROLLER_TOOLS_VERSION ?= v0.16.5

KUSTOMIZE_INSTALL_SCRIPT ?= "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh"
.PHONY: kustomize
Expand All @@ -164,4 +164,4 @@ $(CONTROLLER_GEN): $(LOCALBIN)
.PHONY: envtest
envtest: $(ENVTEST) ## Download envtest-setup locally if necessary.
$(ENVTEST): $(LOCALBIN)
test -s $(LOCALBIN)/setup-envtest || GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-runtime/tools/setup-envtest@release-0.17
test -s $(LOCALBIN)/setup-envtest || GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-runtime/tools/setup-envtest@release-0.19
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ Available statuses:

- `STATUS`: `Running` when the underlying pod is running. The status is copied from the pod status.
- `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.
- `CONFIG`: `loaded` when the startup-configuration is succesfully applied. The status is `failed` when errors occured during startup-configuration load.
- `CONFIG`: `loaded` when the startup-configuration is successfully applied. The status is `failed` when errors occurred during startup-configuration load.

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

Expand Down Expand Up @@ -162,7 +162,7 @@ docker tag ghcr.io/srl-labs/srl-controller:${tag} ghcr.io/srl-labs/srl-controlle
docker push ghcr.io/srl-labs/srl-controller:latest
```

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:
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:

```bash
kustomize build config/default
Expand Down
7 changes: 3 additions & 4 deletions api/v1/srl_version.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package v1

import (
"regexp"
"slices"
"strings"
)

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

// https://regex101.com/r/eWS6Ms/3
Expand Down
148 changes: 148 additions & 0 deletions api/v1/srlinux_helpers.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
/*
Copyright (c) 2021 Nokia. All rights reserved.


Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.

3. Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

package v1

import (
"context"
"fmt"
"strings"

corev1 "k8s.io/api/core/v1"
)

// key value for a combined license file stored in a secret.
const allSecretKey = "all.key"

// GetConfig gets config from srlinux spec.
func (s *SrlinuxSpec) GetConfig() *NodeConfig {
if s.Config != nil {
return s.Config
}

return &NodeConfig{}
}

// GetConstraints gets constraints from srlinux spec,
// default constraints are returned if none are present in the spec.
func (s *SrlinuxSpec) GetConstraints() map[string]string {
if s.Constraints != nil {
return s.Constraints
}

return defaultConstraints
}

// GetModel gets srlinux model (aka variant) from srlinux spec,
// default srlinux variant is returned if none present in the spec.
func (s *SrlinuxSpec) GetModel() string {
if s.Model != "" {
return s.Model
}

return defaultSrlinuxVariant
}

// GetImage returns the srlinux container image name that is used in pod spec
// if Config.Image is provided it takes precedence over all other option
// if not, the Spec.Version is used as a tag for public container image ghcr.io/nokia/srlinux.
func (s *SrlinuxSpec) GetImage() string {
img := defaultSrLinuxImageName

if s.GetConfig().Image != "" {
img = s.GetConfig().Image
}

// when image is not defined, but version is
// the version is used as a tag for a default image repo
if s.GetConfig().Image == "" && s.Version != "" {
img = img + ":" + s.Version
}

return img
}

// GetInitImage gets init container image from the srlinux spec,
// default init container image is returned if none present in the spec.
func (s *SrlinuxSpec) GetInitImage() string {
if s.GetConfig().InitImage != "" {
return s.GetConfig().InitImage
}

return defaultSrlinuxInitContainerImage
}

// GetImageVersion finds an srlinux image version by looking at the Image field of the spec
// as well as at Version field.
// When Version field is set it is returned.
// In other cases, Image string is evaluated and it's tag substring is parsed.
// If no tag is present, or tag is latest, the 0.0 version is assumed to be in use.
func (s *SrlinuxSpec) GetImageVersion() *SrlVersion {
if s.Version != "" {
return parseVersionString(s.Version)
}

var tag string

split := strings.Split(s.GetImage(), ":")
if len(split) == 2 { //nolint:gomnd
tag = split[1]
}

return parseVersionString(tag)
}

// InitLicenseKey sets the Srlinux.LicenseKey to a value of a key
// that matches MAJOR-MINOR.key of a passed secret.
// Where MAJOR-MINOR is retrieved from the image version.
// If such key doesn't exist, it checks if a wildcard `all.key` is found in that secret,
// if nothing found, LicenseKey stays empty, which denotes that no license was found for Srlinux.
func (s *Srlinux) InitLicenseKey(
_ context.Context,
secret *corev1.Secret,
version *SrlVersion,
) {
if secret == nil {
return
}

versionSecretKey := fmt.Sprintf("%s-%s.key", version.Major, version.Minor)
if _, ok := secret.Data[versionSecretKey]; ok {
s.LicenseKey = versionSecretKey

return
}

if _, ok := secret.Data[allSecretKey]; ok {
s.LicenseKey = allSecretKey

return
}
}
Loading