Skip to content

Commit

Permalink
Remove embedded metadata from clusterctl
Browse files Browse the repository at this point in the history
  • Loading branch information
furkatgofurov7 committed Jan 11, 2021
1 parent 995597d commit e4b5725
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 314 deletions.
265 changes: 0 additions & 265 deletions cmd/clusterctl/client/repository/metadata_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package repository

import (
"github.com/pkg/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/serializer"
clusterctlv1 "sigs.k8s.io/cluster-api/cmd/clusterctl/api/v1alpha3"
Expand Down Expand Up @@ -75,11 +74,6 @@ func (f *metadataClient) Get() (*clusterctlv1.Metadata, error) {
log.V(5).Info("Fetching", "File", name, "Provider", f.provider.Name(), "Type", f.provider.Type(), "Version", version)
file, err = f.repository.GetFile(version, name)
if err != nil {
// if there are problems in reading the metadata file from the repository, check if there are embedded metadata for the provider, if yes use them
if obj := f.getEmbeddedMetadata(); obj != nil {
return obj, nil
}

return nil, errors.Wrapf(err, "failed to read %q from the repository for provider %q", name, f.provider.ManifestLabel())
}
} else {
Expand All @@ -98,262 +92,3 @@ func (f *metadataClient) Get() (*clusterctlv1.Metadata, error) {

return obj, nil
}

func (f *metadataClient) getEmbeddedMetadata() *clusterctlv1.Metadata {
// clusterctl includes hard-coded metadata for cluster-API providers developed as a SIG-cluster-lifecycle project in order to
// provide an option for simplifying the release process/the repository management of those projects.
// Embedding metadata in clusterctl is optional, and the metadata.yaml file on the provider repository will always take precedence
// on the embedded one.

// if you are a developer of a SIG-cluster-lifecycle project, you can send a PR to extend the following list.
switch f.provider.Type() {
case clusterctlv1.CoreProviderType:
switch f.provider.Name() {
case config.ClusterAPIProviderName:
return &clusterctlv1.Metadata{
TypeMeta: metav1.TypeMeta{
APIVersion: clusterctlv1.GroupVersion.String(),
Kind: "Metadata",
},
ReleaseSeries: []clusterctlv1.ReleaseSeries{
// v1alpha4 release series
{Major: 0, Minor: 4, Contract: "v1alpha4"},
// v1alpha3 release series
{Major: 0, Minor: 3, Contract: "v1alpha3"},
// v1alpha2 release series are supported only for upgrades
{Major: 0, Minor: 2, Contract: "v1alpha2"},
// older version are not supported by clusterctl
},
}
default:
return nil
}
case clusterctlv1.BootstrapProviderType:
switch f.provider.Name() {
case config.KubeadmBootstrapProviderName:
return &clusterctlv1.Metadata{
TypeMeta: metav1.TypeMeta{
APIVersion: clusterctlv1.GroupVersion.String(),
Kind: "Metadata",
},
ReleaseSeries: []clusterctlv1.ReleaseSeries{
// v1alpha4 release series
{Major: 0, Minor: 4, Contract: "v1alpha4"},
// v1alpha3 release series
{Major: 0, Minor: 3, Contract: "v1alpha3"}, // From this release series CABPK version scheme is linked to CAPI; The 0.2 release series was skipped when doing this change.
// v1alpha2 release series are supported only for upgrades
{Major: 0, Minor: 1, Contract: "v1alpha2"}, // This release was hosted on a different repository
// older version are not supported by clusterctl
},
}
case config.TalosBootstrapProviderName:
return &clusterctlv1.Metadata{
TypeMeta: metav1.TypeMeta{
APIVersion: clusterctlv1.GroupVersion.String(),
Kind: "Metadata",
},
ReleaseSeries: []clusterctlv1.ReleaseSeries{
// v1alpha3 release series
{Major: 0, Minor: 2, Contract: "v1alpha3"},
// v1alpha2 release series are supported only for upgrades
{Major: 0, Minor: 1, Contract: "v1alpha2"},
// older version are not supported by clusterctl
},
}
case config.AWSEKSBootstrapProviderName:
return &clusterctlv1.Metadata{
TypeMeta: metav1.TypeMeta{
APIVersion: clusterctlv1.GroupVersion.String(),
Kind: "Metadata",
},
ReleaseSeries: []clusterctlv1.ReleaseSeries{
// v1alpha3 release series
{Major: 0, Minor: 6, Contract: "v1alpha3"},
},
}
default:
return nil
}
case clusterctlv1.ControlPlaneProviderType:
switch f.provider.Name() {
case config.KubeadmControlPlaneProviderName:
return &clusterctlv1.Metadata{
TypeMeta: metav1.TypeMeta{
APIVersion: clusterctlv1.GroupVersion.String(),
Kind: "Metadata",
},
ReleaseSeries: []clusterctlv1.ReleaseSeries{
// v1alpha4 release series
{Major: 0, Minor: 4, Contract: "v1alpha4"},
// v1alpha3 release series
{Major: 0, Minor: 3, Contract: "v1alpha3"}, // KCP version scheme is linked to CAPI.
// there are no older version for KCP
},
}
case config.TalosControlPlaneProviderName:
return &clusterctlv1.Metadata{
TypeMeta: metav1.TypeMeta{
APIVersion: clusterctlv1.GroupVersion.String(),
Kind: "Metadata",
},
ReleaseSeries: []clusterctlv1.ReleaseSeries{
// v1alpha3 release series
{Major: 0, Minor: 1, Contract: "v1alpha3"},
// there are no older version for Talos controlplane
},
}
case config.AWSEKSControlPlaneProviderName:
return &clusterctlv1.Metadata{
TypeMeta: metav1.TypeMeta{
APIVersion: clusterctlv1.GroupVersion.String(),
Kind: "Metadata",
},
ReleaseSeries: []clusterctlv1.ReleaseSeries{
{Major: 0, Minor: 6, Contract: "v1alpha3"},
},
}
default:
return nil
}
case clusterctlv1.InfrastructureProviderType:
switch f.provider.Name() {
case config.AWSProviderName:
return &clusterctlv1.Metadata{
TypeMeta: metav1.TypeMeta{
APIVersion: clusterctlv1.GroupVersion.String(),
Kind: "Metadata",
},
ReleaseSeries: []clusterctlv1.ReleaseSeries{
// v1alpha3 release series
{Major: 0, Minor: 5, Contract: "v1alpha3"},
// v1alpha2 release series are supported only for upgrades
{Major: 0, Minor: 4, Contract: "v1alpha2"},
// older version are not supported by clusterctl
},
}
case config.AzureProviderName:
return &clusterctlv1.Metadata{
TypeMeta: metav1.TypeMeta{
APIVersion: clusterctlv1.GroupVersion.String(),
Kind: "Metadata",
},
ReleaseSeries: []clusterctlv1.ReleaseSeries{
// v1alpha3 release series
{Major: 0, Minor: 4, Contract: "v1alpha3"},
// v1alpha2 release series are supported only for upgrades
{Major: 0, Minor: 3, Contract: "v1alpha2"},
// older version are not supported by clusterctl
},
}
case config.DOProviderName:
return &clusterctlv1.Metadata{
TypeMeta: metav1.TypeMeta{
APIVersion: clusterctlv1.GroupVersion.String(),
Kind: "Metadata",
},
ReleaseSeries: []clusterctlv1.ReleaseSeries{
// v1alpha3 release series
{Major: 0, Minor: 3, Contract: "v1alpha3"},
// older version are not supported by clusterctl
},
}
case config.DockerProviderName:
// NB. The Docker provider is not designed for production use and is intended for development environments only.
return &clusterctlv1.Metadata{
TypeMeta: metav1.TypeMeta{
APIVersion: clusterctlv1.GroupVersion.String(),
Kind: "Metadata",
},
ReleaseSeries: []clusterctlv1.ReleaseSeries{
// v1alpha4 release series
{Major: 0, Minor: 4, Contract: "v1alpha4"},
// v1alpha3 release series
{Major: 0, Minor: 3, Contract: "v1alpha3"},
// v1alpha2 release series are supported only for upgrades
{Major: 0, Minor: 2, Contract: "v1alpha2"},
// older version are not supported by clusterctl
},
}
case config.GCPProviderName:
return &clusterctlv1.Metadata{
TypeMeta: metav1.TypeMeta{
APIVersion: clusterctlv1.GroupVersion.String(),
Kind: "Metadata",
},
ReleaseSeries: []clusterctlv1.ReleaseSeries{
// v1alpha3 release series
{Major: 0, Minor: 3, Contract: "v1alpha3"},
// older version are not supported by clusterctl
},
}
case config.Metal3ProviderName:
return &clusterctlv1.Metadata{
TypeMeta: metav1.TypeMeta{
APIVersion: clusterctlv1.GroupVersion.String(),
Kind: "Metadata",
},
ReleaseSeries: []clusterctlv1.ReleaseSeries{
// v1alpha3 release series
{Major: 0, Minor: 3, Contract: "v1alpha3"},
// v1alpha2 release series are supported only for upgrades
{Major: 0, Minor: 2, Contract: "v1alpha2"},
// older version are not supported by clusterctl
},
}
case config.PacketProviderName:
return &clusterctlv1.Metadata{
TypeMeta: metav1.TypeMeta{
APIVersion: clusterctlv1.GroupVersion.String(),
Kind: "Metadata",
},
ReleaseSeries: []clusterctlv1.ReleaseSeries{
// v1alpha3 release series
{Major: 0, Minor: 3, Contract: "v1alpha3"},
// older version are not supported by clusterctl
},
}
case config.OpenStackProviderName:
return &clusterctlv1.Metadata{
TypeMeta: metav1.TypeMeta{
APIVersion: clusterctlv1.GroupVersion.String(),
Kind: "Metadata",
},
ReleaseSeries: []clusterctlv1.ReleaseSeries{
// v1alpha3 release series
{Major: 0, Minor: 3, Contract: "v1alpha3"},
},
}
case config.SideroProviderName:
return &clusterctlv1.Metadata{
TypeMeta: metav1.TypeMeta{
APIVersion: clusterctlv1.GroupVersion.String(),
Kind: "Metadata",
},
ReleaseSeries: []clusterctlv1.ReleaseSeries{
// v1alpha3 release series
{Major: 0, Minor: 1, Contract: "v1alpha3"},
// there are no older versions for Sidero
},
}
case config.VSphereProviderName:
return &clusterctlv1.Metadata{
TypeMeta: metav1.TypeMeta{
APIVersion: clusterctlv1.GroupVersion.String(),
Kind: "Metadata",
},
ReleaseSeries: []clusterctlv1.ReleaseSeries{
// v1alpha3 release series
{Major: 0, Minor: 7, Contract: "v1alpha3"},
{Major: 0, Minor: 6, Contract: "v1alpha3"},
// v1alpha2 release series are supported only for upgrades
{Major: 0, Minor: 5, Contract: "v1alpha2"},
// older version are not supported by clusterctl
},
}
default:
return nil
}
default:
return nil
}
}
22 changes: 0 additions & 22 deletions cmd/clusterctl/client/repository/metadata_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,28 +72,6 @@ func Test_metadataClient_Get(t *testing.T) {
},
wantErr: false,
},
{
name: "Pass with embedded metadata",
fields: fields{
provider: config.NewProvider(config.ClusterAPIProviderName, "", clusterctlv1.CoreProviderType),
version: "v1.0.0",
repository: test.NewFakeRepository(). //repository without a metadata file
WithPaths("root", "").
WithDefaultVersion("v1.0.0"),
},
want: &clusterctlv1.Metadata{
TypeMeta: metav1.TypeMeta{
APIVersion: clusterctlv1.GroupVersion.String(),
Kind: "Metadata",
},
ReleaseSeries: []clusterctlv1.ReleaseSeries{
{Major: 0, Minor: 4, Contract: "v1alpha4"},
{Major: 0, Minor: 3, Contract: "v1alpha3"},
{Major: 0, Minor: 2, Contract: "v1alpha2"},
},
},
wantErr: false,
},
{
name: "Fails if the file does not exists",
fields: fields{
Expand Down
Loading

0 comments on commit e4b5725

Please sign in to comment.