Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deploy default-storage-class addon by default #3332

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
36 changes: 32 additions & 4 deletions pkg/addons/ensure.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,22 @@ package addons
import (
"fmt"
"io/fs"
"slices"

"github.com/pkg/errors"

kubeoneapi "k8c.io/kubeone/pkg/apis/kubeone"
"k8c.io/kubeone/pkg/fail"
"k8c.io/kubeone/pkg/state"
"k8c.io/kubeone/pkg/templates/resources"
"k8c.io/kubeone/pkg/templates/weave"

storagev1 "k8s.io/api/storage/v1"
)

const (
// addonLabel is applied to all objects deployed using addons
addonLabel = "kubeone.io/addon"

// defaultStorageClass addon defines name of the default-storage-class addon
defaultStorageClassAddonName = "default-storage-class"
)

// embeddedAddons is a list of addons that are embedded in the KubeOne
Expand Down Expand Up @@ -140,6 +141,32 @@ func collectAddons(s *state.State) []addonAction {
addonsToDeploy = ensureCCMAddons(s, addonsToDeploy)
}

var foundDefaultStorageClass bool

if s.Cluster.Addons != nil && !slices.ContainsFunc(s.Cluster.Addons.Addons, func(addon kubeoneapi.Addon) bool {
return addon.Name == resources.AddonDefaultStorageClass
}) {
var existingStorageClasses storagev1.StorageClassList

if s.DynamicClient != nil {
if err := s.DynamicClient.List(s.Context, &existingStorageClasses); err != nil {
s.Logger.Error(fail.KubeClient(err, "listing existing storage classes"))
}
}

for _, sc := range existingStorageClasses.Items {
if sc.Annotations["storageclass.kubernetes.io/is-default-class"] == "true" {
foundDefaultStorageClass = true
}
}
}

if !foundDefaultStorageClass {
addonsToDeploy = append(addonsToDeploy, addonAction{
name: resources.AddonDefaultStorageClass,
})
}
Comment on lines +164 to +168
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should have a way to disable deployment of this addon. Do we already have that in place?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no. there was no such way.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, with delete: true it will be deleted everytime (which after the first time will have no affect any more). And once the used will have own default SC, this addon will be stopped from adding.


return addonsToDeploy
}

Expand All @@ -162,6 +189,7 @@ func Ensure(s *state.State) error {
return err
}
}

if err := EnsureAddonByName(s, add.name); err != nil {
return err
}
Expand Down Expand Up @@ -224,7 +252,7 @@ func EnsureUserAddons(s *state.State) error {
// NB: We can't migrate StorageClass when applying the CSI driver because
// CSI driver is deployed only for Kubernetes 1.23+ clusters, but this
// issue affects older clusters as well.
if addonName == defaultStorageClassAddonName && s.Cluster.CloudProvider.GCE != nil {
if addonName == resources.AddonDefaultStorageClass && s.Cluster.CloudProvider.GCE != nil {
if err := migrateGCEStandardStorageClass(s); err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/localhelm/helm3.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ import (
"helm.sh/helm/v3/pkg/registry"
helmrelease "helm.sh/helm/v3/pkg/release"
"helm.sh/helm/v3/pkg/storage/driver"
"sigs.k8s.io/yaml"

kubeoneapi "k8c.io/kubeone/pkg/apis/kubeone"
"k8c.io/kubeone/pkg/fail"
Expand All @@ -52,6 +51,7 @@ import (
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
ctrlruntimeclient "sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/yaml"
)

const (
Expand Down
2 changes: 1 addition & 1 deletion pkg/tasks/kubeconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func saveKubeconfig(st *state.State) error {
}

func removeSuperKubeconfig(st *state.State) error {
st.Logger.Info("Removing %s...", superAdminConfPath)
st.Logger.Infof("Removing %s...", superAdminConfPath)

host, err := st.Cluster.Leader()
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions pkg/templates/resources/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ const (
AddonMetricsServer = "metrics-server"
AddonNodeLocalDNS = "nodelocaldns"
AddonOperatingSystemManager = "operating-system-manager"
AddonDefaultStorageClass = "default-storage-class"
)

func CloudAddons() []string {
Expand Down