Skip to content

Commit

Permalink
block clusterctl move and init on Kubernetes v1.22
Browse files Browse the repository at this point in the history
Signed-off-by: Stefan Büringer [email protected]
  • Loading branch information
sbueringer committed Jul 26, 2021
1 parent dfeb8d4 commit 5ce49ff
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 0 deletions.
6 changes: 6 additions & 0 deletions cmd/clusterctl/client/cluster/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ import (

const (
minimumKubernetesVersion = "v1.16.0"
// firstUnsupportedKubernetesVersion is the first version we don't support as management cluster.
// We cannot support v1.22.0 as it's not compatible with our controller-runtime version and WebhookConfigurations v1beta1.
firstUnsupportedKubernetesVersion = "v1.22.0"
)

var (
Expand Down Expand Up @@ -228,6 +231,9 @@ type Proxy interface {
// ValidateKubernetesVersion returns an error if management cluster version less than minimumKubernetesVersion
ValidateKubernetesVersion() error

// ValidateKubernetesMaxVersion returns an error if management cluster version is greater than or equal to firstUnsupportedKubernetesVersion
ValidateKubernetesMaxVersion() error

// NewClient returns a new controller runtime Client object for working on the management cluster
NewClient() (client.Client, error)

Expand Down
25 changes: 25 additions & 0 deletions cmd/clusterctl/client/cluster/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,31 @@ func (k *proxy) ValidateKubernetesVersion() error {
return nil
}

func (k *proxy) ValidateKubernetesMaxVersion() error {
config, err := k.GetConfig()
if err != nil {
return err
}

client := discovery.NewDiscoveryClientForConfigOrDie(config)
serverVersion, err := client.ServerVersion()
if err != nil {
return errors.Wrap(err, "failed to retrieve server version")
}

compver, err := utilversion.MustParseGeneric(serverVersion.String()).Compare(firstUnsupportedKubernetesVersion)
if err != nil {
return errors.Wrap(err, "failed to parse and compare server version")
}

// We want to return an error if the serverVersion is greater or equal than firstUnsupportedKubernetesVersion
if compver >= 0 {
return errors.Errorf("unsupported management cluster server version: %s - versions greater or equal than %s are not supported", serverVersion.String(), firstUnsupportedKubernetesVersion)
}

return nil
}

// GetConfig returns the config for a kubernetes client.
func (k *proxy) GetConfig() (*rest.Config, error) {
config, err := k.configLoadingRules.Load()
Expand Down
4 changes: 4 additions & 0 deletions cmd/clusterctl/client/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ func (c *clusterctlClient) Init(options InitOptions) ([]Components, error) {
return nil, err
}

if err := clusterClient.Proxy().ValidateKubernetesMaxVersion(); err != nil {
return nil, err
}

// ensure the custom resource definitions required by clusterctl are in place
if err := clusterClient.ProviderInventory().EnsureCustomResourceDefinitions(); err != nil {
return nil, err
Expand Down
3 changes: 3 additions & 0 deletions cmd/clusterctl/client/move.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ func (c *clusterctlClient) Move(options MoveOptions) error {
if err != nil {
return err
}
if err := toCluster.Proxy().ValidateKubernetesMaxVersion(); err != nil {
return err
}

// Ensure this command only runs against management clusters with the current Cluster API contract.
if err := toCluster.ProviderInventory().CheckCAPIContract(); err != nil {
Expand Down
4 changes: 4 additions & 0 deletions cmd/clusterctl/internal/test/fake_proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ func (f *FakeProxy) ValidateKubernetesVersion() error {
return nil
}

func (f *FakeProxy) ValidateKubernetesMaxVersion() error {
return nil
}

func (f *FakeProxy) GetConfig() (*rest.Config, error) {
return nil, nil
}
Expand Down

0 comments on commit 5ce49ff

Please sign in to comment.