Skip to content

Commit

Permalink
Fix incorrect output of skuba cluster images
Browse files Browse the repository at this point in the history
Because of v5 regsitry path change, the output of `skuba cluster images`
has incorrect info for v4 related images of previous cluster versions.

The original code has hard-coded registry path for v4, so this will be
fixed in this commit to have adaptive way to have right registry path
for the corresponding cluster version.

Also, `--kubernetes-version` will be kept to use w/o issues.
  • Loading branch information
innobead authored and Pablo Chacin committed Aug 12, 2020
1 parent 4c90849 commit 3271619
Show file tree
Hide file tree
Showing 19 changed files with 171 additions and 109 deletions.
6 changes: 3 additions & 3 deletions internal/pkg/skuba/addons/addons.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ type AddonConfiguration struct {

type addonTemplater func(AddonConfiguration) string
type preflightAddonTemplater func(AddonConfiguration) string
type getImageCallback func(imageTag string) string
type getImageCallback func(clusterVersion *version.Version, imageTag string) string

type renderContext struct {
addon Addon
Expand Down Expand Up @@ -436,10 +436,10 @@ func (addon Addon) Apply(client clientset.Interface, addonConfiguration AddonCon
}

// Images returns the images required for this Addon to properly function
func (addon Addon) Images(imageTag string) []string {
func (addon Addon) Images(clusterVersion *version.Version, imageTag string) []string {
images := []string{}
for _, cb := range addon.getImageCallbacks {
images = append(images, cb(imageTag))
images = append(images, cb(clusterVersion, imageTag))
}
return images
}
Expand Down
19 changes: 10 additions & 9 deletions internal/pkg/skuba/addons/cilium.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package addons

import (
"fmt"
"k8s.io/apimachinery/pkg/util/version"
"strings"

"github.com/SUSE/skuba/internal/pkg/skuba/addons/cilium_manifests"
Expand All @@ -35,28 +36,28 @@ func init() {
registerAddon(kubernetes.Cilium, CniAddOn, renderCiliumTemplate, renderCiliumPreflightTemplate, ciliumCallbacks{}, normalPriority, []getImageCallback{GetCiliumInitImage, GetCiliumOperatorImage, GetCiliumImage})
}

func GetCiliumInitImage(imageTag string) string {
return images.GetGenericImage(skubaconstants.ImageRepository, "cilium-init", imageTag)
func GetCiliumInitImage(clusterVersion *version.Version, imageTag string) string {
return images.GetGenericImage(skubaconstants.ImageRepository(clusterVersion), "cilium-init", imageTag)
}

func GetCiliumOperatorImage(imageTag string) string {
return images.GetGenericImage(skubaconstants.ImageRepository, "cilium-operator", imageTag)
func GetCiliumOperatorImage(clusterVersion *version.Version, imageTag string) string {
return images.GetGenericImage(skubaconstants.ImageRepository(clusterVersion), "cilium-operator", imageTag)
}

func GetCiliumImage(imageTag string) string {
return images.GetGenericImage(skubaconstants.ImageRepository, "cilium", imageTag)
func GetCiliumImage(clusterVersion *version.Version, imageTag string) string {
return images.GetGenericImage(skubaconstants.ImageRepository(clusterVersion), "cilium", imageTag)
}

func (renderContext renderContext) CiliumInitImage() string {
return GetCiliumInitImage(kubernetes.AddonVersionForClusterVersion(kubernetes.Cilium, renderContext.config.ClusterVersion).Version)
return GetCiliumInitImage(renderContext.config.ClusterVersion, kubernetes.AddonVersionForClusterVersion(kubernetes.Cilium, renderContext.config.ClusterVersion).Version)
}

func (renderContext renderContext) CiliumOperatorImage() string {
return GetCiliumOperatorImage(kubernetes.AddonVersionForClusterVersion(kubernetes.Cilium, renderContext.config.ClusterVersion).Version)
return GetCiliumOperatorImage(renderContext.config.ClusterVersion, kubernetes.AddonVersionForClusterVersion(kubernetes.Cilium, renderContext.config.ClusterVersion).Version)
}

func (renderContext renderContext) CiliumImage() string {
return GetCiliumImage(kubernetes.AddonVersionForClusterVersion(kubernetes.Cilium, renderContext.config.ClusterVersion).Version)
return GetCiliumImage(renderContext.config.ClusterVersion, kubernetes.AddonVersionForClusterVersion(kubernetes.Cilium, renderContext.config.ClusterVersion).Version)
}

func renderCiliumTemplate(addonConfiguration AddonConfiguration) string {
Expand Down
76 changes: 46 additions & 30 deletions internal/pkg/skuba/addons/cilium_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package addons

import (
"fmt"
"regexp"
"testing"

Expand All @@ -37,21 +38,26 @@ func TestGetCiliumInitImage(t *testing.T) {
{
name: "get cilium init image without revision",
imageTag: "1.7.5",
want: img.ImageRepository + "/cilium-init:1.7.5",
want: "cilium-init:1.7.5",
},
{
name: "get cilium init image with revision",
imageTag: "1.7.5-rev2",
want: img.ImageRepository + "/cilium-init:1.7.5-rev2",
want: "cilium-init:1.7.5-rev2",
},
}
for _, tt := range tests {
tt := tt // Parallel testing
t.Run(tt.name, func(t *testing.T) {
if got := GetCiliumInitImage(tt.imageTag); got != tt.want {
t.Errorf("GetCiliumInitImage() = %v, want %v", got, tt.want)
}
})

for _, ver := range kubernetes.AvailableVersions() {
for _, tt := range tests {
tt := tt // Parallel testing
t.Run(tt.name, func(t *testing.T) {
imageUri := fmt.Sprintf("%s/%s", img.ImageRepository(ver), tt.want)

if got := GetCiliumInitImage(ver, tt.imageTag); got != imageUri {
t.Errorf("GetCiliumInitImage() = %v, want %v", got, tt.want)
}
})
}
}
}

Expand All @@ -64,21 +70,26 @@ func TestGetCiliumOperatorImage(t *testing.T) {
{
name: "get cilium operator image without revision",
imageTag: "1.7.5",
want: img.ImageRepository + "/cilium-operator:1.7.5",
want: "cilium-operator:1.7.5",
},
{
name: "get cilium operator image with revision",
imageTag: "1.7.5-rev2",
want: img.ImageRepository + "/cilium-operator:1.7.5-rev2",
want: "cilium-operator:1.7.5-rev2",
},
}
for _, tt := range tests {
tt := tt // Parallel testing
t.Run(tt.name, func(t *testing.T) {
if got := GetCiliumOperatorImage(tt.imageTag); got != tt.want {
t.Errorf("GetCiliumOperatorImage() = %v, want %v", got, tt.want)
}
})

for _, ver := range kubernetes.AvailableVersions() {
for _, tt := range tests {
tt := tt // Parallel testing
t.Run(tt.name, func(t *testing.T) {
imageUri := fmt.Sprintf("%s/%s", img.ImageRepository(ver), tt.want)

if got := GetCiliumOperatorImage(ver, tt.imageTag); got != imageUri {
t.Errorf("GetCiliumOperatorImage() = %v, want %v", got, imageUri)
}
})
}
}
}

Expand All @@ -91,21 +102,26 @@ func TestGetCiliumImage(t *testing.T) {
{
name: "get cilium image without revision",
imageTag: "1.7.5",
want: img.ImageRepository + "/cilium:1.7.5",
want: "cilium:1.7.5",
},
{
name: "get cilium image with revision",
imageTag: "1.7.5-rev2",
want: img.ImageRepository + "/cilium:1.7.5-rev2",
want: "cilium:1.7.5-rev2",
},
}
for _, tt := range tests {
tt := tt // Parallel testing
t.Run(tt.name, func(t *testing.T) {
if got := GetCiliumImage(tt.imageTag); got != tt.want {
t.Errorf("GetCiliumImage() = %v, want %v", got, tt.want)
}
})

for _, ver := range kubernetes.AvailableVersions() {
for _, tt := range tests {
tt := tt // Parallel testing
t.Run(tt.name, func(t *testing.T) {
imageUri := fmt.Sprintf("%s/%s", img.ImageRepository(ver), tt.want)

if got := GetCiliumImage(ver, tt.imageTag); got != imageUri {
t.Errorf("GetCiliumImage() = %v, want %v", got, tt.want)
}
})
}
}
}

Expand All @@ -125,7 +141,7 @@ func Test_renderContext_CiliumInitImage(t *testing.T) {
ClusterName: "",
},
},
want: img.ImageRepository + "/cilium-init:([[:digit:]]{1,}.){2}[[:digit:]]{1,}(-rev[:digit:]{1,})?",
want: img.ImageRepository(ver) + "/cilium-init:([[:digit:]]{1,}.){2}[[:digit:]]{1,}(-rev[:digit:]{1,})?",
}
t.Run(tt.name, func(t *testing.T) {
got := tt.renderContext.CiliumInitImage()
Expand Down Expand Up @@ -158,7 +174,7 @@ func Test_renderContext_CiliumOperatorImage(t *testing.T) {
ClusterName: "",
},
},
want: img.ImageRepository + "/cilium-operator:([[:digit:]]{1,}.){2}[[:digit:]]{1,}(-rev[:digit:]{1,})?",
want: img.ImageRepository(ver) + "/cilium-operator:([[:digit:]]{1,}.){2}[[:digit:]]{1,}(-rev[:digit:]{1,})?",
}
t.Run(tt.name, func(t *testing.T) {
got := tt.renderContext.CiliumOperatorImage()
Expand Down Expand Up @@ -191,7 +207,7 @@ func Test_renderContext_CiliumImage(t *testing.T) {
ClusterName: "",
},
},
want: img.ImageRepository + "/cilium:([[:digit:]]{1,}.){2}[[:digit:]]{1,}(-rev[:digit:]{1,})?",
want: img.ImageRepository(ver) + "/cilium:([[:digit:]]{1,}.){2}[[:digit:]]{1,}(-rev[:digit:]{1,})?",
}
t.Run(tt.name, func(t *testing.T) {
got := tt.renderContext.CiliumImage()
Expand Down
7 changes: 4 additions & 3 deletions internal/pkg/skuba/addons/dex.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package addons

import (
"github.com/pkg/errors"
"k8s.io/apimachinery/pkg/util/version"
clientset "k8s.io/client-go/kubernetes"
"k8s.io/kubernetes/cmd/kubeadm/app/images"

Expand All @@ -33,12 +34,12 @@ func init() {
registerAddon(kubernetes.Dex, GenericAddOn, renderDexTemplate, nil, dexCallbacks{}, normalPriority, []getImageCallback{GetDexImage})
}

func GetDexImage(imageTag string) string {
return images.GetGenericImage(skubaconstants.ImageRepository, "caasp-dex", imageTag)
func GetDexImage(clusterVersion *version.Version, imageTag string) string {
return images.GetGenericImage(skubaconstants.ImageRepository(clusterVersion), "caasp-dex", imageTag)
}

func (renderContext renderContext) DexImage() string {
return GetDexImage(kubernetes.AddonVersionForClusterVersion(kubernetes.Dex, renderContext.config.ClusterVersion).Version)
return GetDexImage(renderContext.config.ClusterVersion, kubernetes.AddonVersionForClusterVersion(kubernetes.Dex, renderContext.config.ClusterVersion).Version)
}

func renderDexTemplate(addonConfiguration AddonConfiguration) string {
Expand Down
26 changes: 16 additions & 10 deletions internal/pkg/skuba/addons/dex_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package addons

import (
"fmt"
"regexp"
"testing"

Expand All @@ -37,21 +38,26 @@ func TestGetDexImage(t *testing.T) {
{
name: "get dex init image without revision",
imageTag: "2.16.0",
want: img.ImageRepository + "/caasp-dex:2.16.0",
want: "caasp-dex:2.16.0",
},
{
name: "get dex init image with revision",
imageTag: "2.16.0-rev2",
want: img.ImageRepository + "/caasp-dex:2.16.0-rev2",
want: "caasp-dex:2.16.0-rev2",
},
}
for _, tt := range tests {
tt := tt // Parallel testing
t.Run(tt.name, func(t *testing.T) {
if got := GetDexImage(tt.imageTag); got != tt.want {
t.Errorf("GetDexImage() = %v, want %v", got, tt.want)
}
})

for _, ver := range kubernetes.AvailableVersions() {
for _, tt := range tests {
tt := tt // Parallel testing
t.Run(tt.name, func(t *testing.T) {
imageUri := fmt.Sprintf("%s/%s", img.ImageRepository(ver), tt.want)

if got := GetDexImage(ver, tt.imageTag); got != imageUri {
t.Errorf("GetDexImage() = %v, want %v", got, imageUri)
}
})
}
}
}

Expand All @@ -71,7 +77,7 @@ func Test_renderContext_DexImage(t *testing.T) {
ClusterName: "",
},
},
want: img.ImageRepository + "/caasp-dex:([[:digit:]]{1,}.){2}[[:digit:]]{1,}(-rev[:digit:]{1,})?",
want: img.ImageRepository(ver) + "/caasp-dex:([[:digit:]]{1,}.){2}[[:digit:]]{1,}(-rev[:digit:]{1,})?",
}
t.Run(tt.name, func(t *testing.T) {
got := tt.renderContext.DexImage()
Expand Down
7 changes: 4 additions & 3 deletions internal/pkg/skuba/addons/gangway.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package addons

import (
"github.com/pkg/errors"
"k8s.io/apimachinery/pkg/util/version"
clientset "k8s.io/client-go/kubernetes"
"k8s.io/kubernetes/cmd/kubeadm/app/images"

Expand All @@ -33,12 +34,12 @@ func init() {
registerAddon(kubernetes.Gangway, GenericAddOn, renderGangwayTemplate, nil, gangwayCallbacks{}, normalPriority, []getImageCallback{GetGangwayImage})
}

func GetGangwayImage(imageTag string) string {
return images.GetGenericImage(skubaconstants.ImageRepository, "gangway", imageTag)
func GetGangwayImage(clusterVersion *version.Version, imageTag string) string {
return images.GetGenericImage(skubaconstants.ImageRepository(clusterVersion), "gangway", imageTag)
}

func (renderContext renderContext) GangwayImage() string {
return GetGangwayImage(kubernetes.AddonVersionForClusterVersion(kubernetes.Gangway, renderContext.config.ClusterVersion).Version)
return GetGangwayImage(renderContext.config.ClusterVersion, kubernetes.AddonVersionForClusterVersion(kubernetes.Gangway, renderContext.config.ClusterVersion).Version)
}

func renderGangwayTemplate(addonConfiguration AddonConfiguration) string {
Expand Down
26 changes: 16 additions & 10 deletions internal/pkg/skuba/addons/gangway_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package addons

import (
"fmt"
"regexp"
"testing"

Expand All @@ -37,21 +38,26 @@ func TestGetGangwayImage(t *testing.T) {
{
name: "get gangway init image without revision",
imageTag: "3.1.0",
want: img.ImageRepository + "/gangway:3.1.0",
want: "gangway:3.1.0",
},
{
name: "get gangway init image with revision",
imageTag: "3.1.0-rev2",
want: img.ImageRepository + "/gangway:3.1.0-rev2",
want: "gangway:3.1.0-rev2",
},
}
for _, tt := range tests {
tt := tt // Parallel testing
t.Run(tt.name, func(t *testing.T) {
if got := GetGangwayImage(tt.imageTag); got != tt.want {
t.Errorf("GetGangwayImage() = %v, want %v", got, tt.want)
}
})

for _, ver := range kubernetes.AvailableVersions() {
for _, tt := range tests {
tt := tt // Parallel testing
t.Run(tt.name, func(t *testing.T) {
imageUri := fmt.Sprintf("%s/%s", img.ImageRepository(ver), tt.want)

if got := GetGangwayImage(ver, tt.imageTag); got != imageUri {
t.Errorf("GetGangwayImage() = %v, want %v", got, imageUri)
}
})
}
}
}

Expand All @@ -71,7 +77,7 @@ func Test_renderContext_GangwayImage(t *testing.T) {
ClusterName: "",
},
},
want: img.ImageRepository + "/gangway:([[:digit:]]{1,}.){2}[[:digit:]]{1,}(-rev[:digit:]{1,})?",
want: img.ImageRepository(ver) + "/gangway:([[:digit:]]{1,}.){2}[[:digit:]]{1,}(-rev[:digit:]{1,})?",
}
t.Run(tt.name, func(t *testing.T) {
got := tt.renderContext.GangwayImage()
Expand Down
7 changes: 4 additions & 3 deletions internal/pkg/skuba/addons/kucero.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package addons

import (
"k8s.io/apimachinery/pkg/util/version"
"k8s.io/kubernetes/cmd/kubeadm/app/images"

"github.com/SUSE/skuba/internal/pkg/skuba/kubernetes"
Expand All @@ -28,12 +29,12 @@ func init() {
registerAddon(kubernetes.Kucero, GenericAddOn, renderKuceroTemplate, nil, nil, normalPriority, []getImageCallback{GetKuceroImage})
}

func GetKuceroImage(imageTag string) string {
return images.GetGenericImage(skubaconstants.ImageRepository, "kucero", imageTag)
func GetKuceroImage(clusterVersion *version.Version, imageTag string) string {
return images.GetGenericImage(skubaconstants.ImageRepository(clusterVersion), "kucero", imageTag)
}

func (renderContext renderContext) KuceroImage() string {
return GetKuceroImage(kubernetes.AddonVersionForClusterVersion(kubernetes.Kucero, renderContext.config.ClusterVersion).Version)
return GetKuceroImage(renderContext.config.ClusterVersion, kubernetes.AddonVersionForClusterVersion(kubernetes.Kucero, renderContext.config.ClusterVersion).Version)
}

func renderKuceroTemplate(addonConfiguration AddonConfiguration) string {
Expand Down
Loading

0 comments on commit 3271619

Please sign in to comment.