Skip to content

Commit

Permalink
Merge pull request #1390 from rktidwell/maintenance-caasp-v4.2
Browse files Browse the repository at this point in the history
Revert "Merge pull request #1384 from mrostecki/4.2-remove-cilium-init"
  • Loading branch information
vadorovsky authored Oct 9, 2020
2 parents 6e66730 + a019c91 commit ae53e81
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 1 deletion.
10 changes: 9 additions & 1 deletion internal/pkg/skuba/addons/cilium.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@ import (
)

func init() {
registerAddon(kubernetes.Cilium, renderCiliumTemplate, renderCiliumPreflightTemplate, ciliumCallbacks{}, normalPriority, []getImageCallback{GetCiliumOperatorImage, GetCiliumImage})
registerAddon(kubernetes.Cilium, renderCiliumTemplate, renderCiliumPreflightTemplate, ciliumCallbacks{}, normalPriority, []getImageCallback{GetCiliumInitImage, GetCiliumOperatorImage, GetCiliumImage})
}

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

func GetCiliumOperatorImage(imageTag string) string {
Expand All @@ -42,6 +46,10 @@ func GetCiliumImage(imageTag string) string {
return images.GetGenericImage(skubaconstants.ImageRepository, "cilium", imageTag)
}

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

func (renderContext renderContext) CiliumOperatorImage() string {
return GetCiliumOperatorImage(kubernetes.AddonVersionForClusterVersion(kubernetes.Cilium, renderContext.config.ClusterVersion).Version)
}
Expand Down
60 changes: 60 additions & 0 deletions internal/pkg/skuba/addons/cilium_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,33 @@ import (
img "github.com/SUSE/skuba/pkg/skuba"
)

func TestGetCiliumInitImage(t *testing.T) {
tests := []struct {
name string
imageTag string
want string
}{
{
name: "get cilium init image without revision",
imageTag: "1.6.6",
want: img.ImageRepository + "/cilium-init:1.6.6",
},
{
name: "get cilium init image with revision",
imageTag: "1.6.6-rev2",
want: img.ImageRepository + "/cilium-init:1.6.6-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)
}
})
}
}

func TestGetCiliumOperatorImage(t *testing.T) {
tests := []struct {
name string
Expand Down Expand Up @@ -82,6 +109,39 @@ func TestGetCiliumImage(t *testing.T) {
}
}

func Test_renderContext_CiliumInitImage(t *testing.T) {
type test struct {
name string
renderContext renderContext
want string
}
for _, ver := range kubernetes.AvailableVersions() {
tt := test{
name: "render Cilium Init Image URL when cluster version is " + ver.String(),
renderContext: renderContext{
config: AddonConfiguration{
ClusterVersion: ver,
ControlPlane: "",
ClusterName: "",
},
},
want: img.ImageRepository + "/cilium-init:([[:digit:]]{1,}.){2}[[:digit:]]{1,}(-rev[:digit:]{1,})?",
}
t.Run(tt.name, func(t *testing.T) {
got := tt.renderContext.CiliumInitImage()
matched, err := regexp.Match(tt.want, []byte(got))
if err != nil {
t.Error(err)
return
}
if !matched {
t.Errorf("renderContext.CiliumInitImage() = %v, want %v", got, tt.want)
return
}
})
}
}

func Test_renderContext_CiliumOperatorImage(t *testing.T) {
type test struct {
name string
Expand Down

0 comments on commit ae53e81

Please sign in to comment.