Use enums for needsRollingUpdate in the channels API

This commit is contained in:
Ole Markus With 2022-12-20 20:50:02 +01:00
parent d9e2490439
commit 43be10020c
5 changed files with 19 additions and 11 deletions

View File

@ -35,6 +35,14 @@ type AddonsSpec struct {
Addons []*AddonSpec `json:"addons,omitempty"`
}
type NeedsRollingUpdate string
const (
NeedsRollingUpdateControlPlane NeedsRollingUpdate = "control-plane"
NeedsRollingUpdateWorkers NeedsRollingUpdate = "workers"
NeedsRollingUpdateAll NeedsRollingUpdate = "all"
)
type AddonSpec struct {
Name *string `json:"name,omitempty"`
@ -63,7 +71,7 @@ type AddonSpec struct {
// NeedsRollingUpdate determines if we should mark nodes as needing an update.
// Legal values are control-plane, workers, and all
// Empty value means no update needed
NeedsRollingUpdate string `json:"needsRollingUpdate,omitempty"`
NeedsRollingUpdate NeedsRollingUpdate `json:"needsRollingUpdate,omitempty"`
// NeedsPKI determines if channels should provision a CA and a cert-manager issuer for the addon.
NeedsPKI bool `json:"needsPKI,omitempty"`

View File

@ -233,9 +233,9 @@ func (a *Addon) patchNeedsUpdateLabel(ctx context.Context, k8sClient kubernetes.
klog.Infof("addon %v wants to update %v nodes", a.Name, a.Spec.NeedsRollingUpdate)
selector := ""
switch a.Spec.NeedsRollingUpdate {
case "control-plane":
case api.NeedsRollingUpdateControlPlane:
selector = "node-role.kubernetes.io/master="
case "worker":
case api.NeedsRollingUpdateWorkers:
selector = "node-role.kubernetes.io/node="
}

View File

@ -175,7 +175,7 @@ func Test_NeedsRollingUpdate(t *testing.T) {
Spec: &api.AddonSpec{
Name: fi.PtrTo("test"),
ManifestHash: "originalHash",
NeedsRollingUpdate: "all",
NeedsRollingUpdate: api.NeedsRollingUpdateAll,
},
},
},
@ -185,7 +185,7 @@ func Test_NeedsRollingUpdate(t *testing.T) {
Spec: &api.AddonSpec{
Name: fi.PtrTo("test"),
ManifestHash: "newHash",
NeedsRollingUpdate: "all",
NeedsRollingUpdate: api.NeedsRollingUpdateAll,
},
},
updateRequired: true,
@ -197,7 +197,7 @@ func Test_NeedsRollingUpdate(t *testing.T) {
Spec: &api.AddonSpec{
Name: fi.PtrTo("test"),
ManifestHash: "newHash",
NeedsRollingUpdate: "worker",
NeedsRollingUpdate: api.NeedsRollingUpdateWorkers,
},
},
updateRequired: true,
@ -209,7 +209,7 @@ func Test_NeedsRollingUpdate(t *testing.T) {
Spec: &api.AddonSpec{
Name: fi.PtrTo("test"),
ManifestHash: "newHash",
NeedsRollingUpdate: "control-plane",
NeedsRollingUpdate: api.NeedsRollingUpdateControlPlane,
},
},
updateRequired: true,
@ -221,7 +221,7 @@ func Test_NeedsRollingUpdate(t *testing.T) {
Spec: &api.AddonSpec{
Name: fi.PtrTo("test"),
ManifestHash: "newHash",
NeedsRollingUpdate: "all",
NeedsRollingUpdate: api.NeedsRollingUpdateAll,
},
},
originalAnnotations: map[string]string{

View File

@ -340,7 +340,7 @@ func (b *BootstrapChannelBuilder) buildAddons(c *fi.CloudupModelBuilderContext)
Name: fi.PtrTo(key),
Selector: map[string]string{"k8s-addon": key},
Manifest: fi.PtrTo(location),
NeedsRollingUpdate: "control-plane",
NeedsRollingUpdate: channelsapi.NeedsRollingUpdateControlPlane,
Id: id,
})
}
@ -1057,7 +1057,7 @@ func (b *BootstrapChannelBuilder) buildAddons(c *fi.CloudupModelBuilderContext)
Selector: networkingSelector(),
Manifest: fi.PtrTo(location),
Id: id,
NeedsRollingUpdate: "all",
NeedsRollingUpdate: channelsapi.NeedsRollingUpdateAll,
})
}
}

View File

@ -35,7 +35,7 @@ func addCiliumAddon(b *BootstrapChannelBuilder, addons *AddonList) error {
Selector: networkingSelector(),
Manifest: fi.PtrTo(location),
Id: id,
NeedsRollingUpdate: "all",
NeedsRollingUpdate: api.NeedsRollingUpdateAll,
}
if cilium.Hubble != nil && fi.ValueOf(cilium.Hubble.Enabled) {
addon.NeedsPKI = true