Skip to content

Commit

Permalink
Merge pull request #2522 from fabriziopandini/clusterctl-fix-upgrade
Browse files Browse the repository at this point in the history
🐛clusterctl: fix upgrade
  • Loading branch information
k8s-ci-robot authored Mar 4, 2020
2 parents 25a933a + b06b0cd commit 952a1d9
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 4 deletions.
8 changes: 5 additions & 3 deletions cmd/clusterctl/client/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,11 @@ func (c *clusterctlClient) ApplyUpgrade(options ApplyUpgradeOptions) error {
// Converts upgrade references back into an UpgradeItem.
upgradeItems := []cluster.UpgradeItem{}

upgradeItems, err = addUpgradeItems(upgradeItems, clusterctlv1.CoreProviderType, options.CoreProvider)
if err != nil {
return err
if options.CoreProvider != "" {
upgradeItems, err = addUpgradeItems(upgradeItems, clusterctlv1.CoreProviderType, options.CoreProvider)
if err != nil {
return err
}
}
upgradeItems, err = addUpgradeItems(upgradeItems, clusterctlv1.BootstrapProviderType, options.BootstrapProviders...)
if err != nil {
Expand Down
60 changes: 59 additions & 1 deletion cmd/clusterctl/client/upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func Test_clusterctlClient_ApplyUpgrade(t *testing.T) {
wantErr: false,
},
{
name: "apply a custom plan",
name: "apply a custom plan - core provider only",
fields: fields{
client: fakeClientFoUpgrade(), // core v1.0.0 (v1.0.1 available), infra v2.0.0 (v2.0.1 available)
},
Expand Down Expand Up @@ -101,6 +101,64 @@ func Test_clusterctlClient_ApplyUpgrade(t *testing.T) {
},
wantErr: false,
},
{
name: "apply a custom plan - infra provider only",
fields: fields{
client: fakeClientFoUpgrade(), // core v1.0.0 (v1.0.1 available), infra v2.0.0 (v2.0.1 available)
},
args: args{
options: ApplyUpgradeOptions{
Kubeconfig: "kubeconfig",
ManagementGroup: "cluster-api-system/cluster-api",
Contract: "",
CoreProvider: "",
BootstrapProviders: nil,
ControlPlaneProviders: nil,
InfrastructureProviders: []string{"infra-system/infra:v2.0.1"},
},
},
wantProviders: &clusterctlv1.ProviderList{
TypeMeta: metav1.TypeMeta{
APIVersion: clusterctlv1.GroupVersion.String(),
Kind: "ProviderList",
},
ListMeta: metav1.ListMeta{},
Items: []clusterctlv1.Provider{ // only one provider should be upgraded
fakeProvider("cluster-api", clusterctlv1.CoreProviderType, "v1.0.0", "cluster-api-system"),
fakeProvider("infra", clusterctlv1.InfrastructureProviderType, "v2.0.1", "infra-system"),
},
},
wantErr: false,
},
{
name: "apply a custom plan - both providers",
fields: fields{
client: fakeClientFoUpgrade(), // core v1.0.0 (v1.0.1 available), infra v2.0.0 (v2.0.1 available)
},
args: args{
options: ApplyUpgradeOptions{
Kubeconfig: "kubeconfig",
ManagementGroup: "cluster-api-system/cluster-api",
Contract: "",
CoreProvider: "cluster-api-system/cluster-api:v1.0.1",
BootstrapProviders: nil,
ControlPlaneProviders: nil,
InfrastructureProviders: []string{"infra-system/infra:v2.0.1"},
},
},
wantProviders: &clusterctlv1.ProviderList{
TypeMeta: metav1.TypeMeta{
APIVersion: clusterctlv1.GroupVersion.String(),
Kind: "ProviderList",
},
ListMeta: metav1.ListMeta{},
Items: []clusterctlv1.Provider{ // only one provider should be upgraded
fakeProvider("cluster-api", clusterctlv1.CoreProviderType, "v1.0.1", "cluster-api-system"),
fakeProvider("infra", clusterctlv1.InfrastructureProviderType, "v2.0.1", "infra-system"),
},
},
wantErr: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down

0 comments on commit 952a1d9

Please sign in to comment.