Skip to content

Commit f8a383f

Browse files
authored
Pin the default client image with digest (#227)
This changes the default client image from latest to a pinned digest. It also enforces that the default image version tag matches the version of the Netbird dependency. This makes testing a lot easier and also ensures that we wont get untested behavior introduced if the client makes a breaking change. Signed-off-by: Philip Laine <philip.laine@gmail.com>
1 parent ebe2149 commit f8a383f

5 files changed

Lines changed: 48 additions & 2 deletions

File tree

cmd/main.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ import (
4848
nbv1 "github.com/netbirdio/kubernetes-operator/api/v1"
4949
nbv1alpha1 "github.com/netbirdio/kubernetes-operator/api/v1alpha1"
5050
"github.com/netbirdio/kubernetes-operator/internal/controller"
51+
"github.com/netbirdio/kubernetes-operator/internal/version"
5152
nbwebhookv1 "github.com/netbirdio/kubernetes-operator/internal/webhook/v1"
5253
)
5354

@@ -84,7 +85,7 @@ func main() {
8485
)
8586
flag.StringVar(&runtimeNamespace, "runtime-namespace", "", "Namespace the controller is running in")
8687
flag.StringVar(&managementURL, "netbird-management-url", "https://api.netbird.io", "Management service URL")
87-
flag.StringVar(&clientImage, "netbird-client-image", "netbirdio/netbird:latest", "Image for netbird client container")
88+
flag.StringVar(&clientImage, "netbird-client-image", "", "Image for netbird client container")
8889
flag.StringVar(
8990
&clusterName,
9091
"cluster-name",
@@ -148,6 +149,10 @@ func main() {
148149
os.Exit(1)
149150
}
150151

152+
if clientImage == "" {
153+
clientImage = version.ClientImage()
154+
}
155+
151156
defaultLabelsMap := make(map[string]string)
152157
if defaultLabels != "" {
153158
for s := range strings.SplitSeq(defaultLabels, ",") {

go.mod

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@ toolchain go1.26.1
77
require (
88
github.com/fluxcd/pkg/runtime v0.105.0
99
github.com/go-logr/logr v1.4.3
10+
github.com/go-openapi/testify/v2 v2.5.0
1011
github.com/google/uuid v1.6.0
1112
github.com/netbirdio/netbird v0.70.4
1213
github.com/onsi/ginkgo/v2 v2.28.3
1314
github.com/onsi/gomega v1.40.0
15+
golang.org/x/mod v0.35.0
1416
k8s.io/api v0.36.0
1517
k8s.io/apimachinery v0.36.0
1618
k8s.io/client-go v0.36.0
@@ -79,7 +81,6 @@ require (
7981
go.yaml.in/yaml/v2 v2.4.3 // indirect
8082
go.yaml.in/yaml/v3 v3.0.4 // indirect
8183
golang.org/x/crypto v0.50.0 // indirect
82-
golang.org/x/mod v0.35.0 // indirect
8384
golang.org/x/net v0.53.0 // indirect
8485
golang.org/x/oauth2 v0.36.0 // indirect
8586
golang.org/x/sync v0.20.0 // indirect

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,8 @@ github.com/go-openapi/jsonreference v0.21.0 h1:Rs+Y7hSXT83Jacb7kFyjn4ijOuVGSvOdF
159159
github.com/go-openapi/jsonreference v0.21.0/go.mod h1:LmZmgsrTkVg9LG4EaHeY8cBDslNPMo06cago5JNLkm4=
160160
github.com/go-openapi/swag v0.23.1 h1:lpsStH0n2ittzTnbaSloVZLuB5+fvSY/+hnagBjSNZU=
161161
github.com/go-openapi/swag v0.23.1/go.mod h1:STZs8TbRvEQQKUA+JZNAm3EWlgaOBGpyFDqQnDHMef0=
162+
github.com/go-openapi/testify/v2 v2.5.0 h1:UOCr63aAsMIDydZbZGqo5Ev01D4eydItRbekDuZMJLw=
163+
github.com/go-openapi/testify/v2 v2.5.0/go.mod h1:SgsVHtfooshd0tublTtJ50FPKhujf47YRqauXXOUxfw=
162164
github.com/go-sql-driver/mysql v1.9.3 h1:U/N249h2WzJ3Ukj8SowVFjdtZKfu9vlLZxjPXV1aweo=
163165
github.com/go-sql-driver/mysql v1.9.3/go.mod h1:qn46aNg1333BRMNU69Lq93t8du/dwxI64Gl8i5p1WMU=
164166
github.com/go-task/slim-sprig/v3 v3.0.0 h1:sUs3vkvUymDpBKi3qH1YSqBQk9+9D/8M2mN1vB6EwHI=

internal/version/version.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package version
2+
3+
func ClientImage() string {
4+
return "ghcr.io/netbirdio/netbird:0.70.4@sha256:3a28b9f7f32875c6a35f952ca7e9cb688b1e610365365ff55f6e790da3950f55"
5+
}

internal/version/version_test.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package version
2+
3+
import (
4+
"os"
5+
"slices"
6+
"strings"
7+
"testing"
8+
9+
"golang.org/x/mod/modfile"
10+
11+
"github.com/go-openapi/testify/v2/require"
12+
)
13+
14+
func TestClientImage(t *testing.T) {
15+
t.Parallel()
16+
17+
b, err := os.ReadFile("../../go.mod")
18+
require.NoError(t, err)
19+
f, err := modfile.Parse("go.mod", b, nil)
20+
require.NoError(t, err)
21+
idx := slices.IndexFunc(f.Require, func(r *modfile.Require) bool {
22+
return r.Mod.Path == "github.com/netbirdio/netbird"
23+
})
24+
require.GreaterT(t, idx, -1)
25+
modVersion := strings.TrimPrefix(f.Require[idx].Mod.Version, "v")
26+
27+
clientImg := ClientImage()
28+
start := strings.Index(clientImg, ":") + 1
29+
end := strings.Index(clientImg, "@")
30+
imgVersion := clientImg[start:end]
31+
32+
require.EqualT(t, modVersion, imgVersion)
33+
}

0 commit comments

Comments
 (0)