Skip to content

Commit 3b4afd9

Browse files
José SilvaJosé Silva
authored andcommitted
fix: returning an error when vcluster config schema changed
1 parent 8d3daf7 commit 3b4afd9

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

config/config.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
var Values string
2424

2525
var ErrInvalidConfig = errors.New("invalid config")
26+
var ErrInvalidPrivateNodesConfig = errors.New("invalid private nodes config")
2627

2728
// NewDefaultConfig creates a new config based on the values.yaml, including all default values.
2829
func NewDefaultConfig() (*Config, error) {
@@ -118,6 +119,18 @@ type PrivateNodes struct {
118119
VPN PrivateNodesVPN `json:"vpn,omitempty"`
119120
}
120121

122+
// UnmarshalJSON makes the schema change return a custom error for invalid private nodes config
123+
func (p *PrivateNodes) UnmarshalJSON(data []byte) error {
124+
type PrivateNodesAlias PrivateNodes
125+
var alias PrivateNodesAlias
126+
if err := json.Unmarshal(data, &alias); err != nil {
127+
return fmt.Errorf("%w: %v", ErrInvalidPrivateNodesConfig, err)
128+
}
129+
// Copy the unmarshaled data
130+
*p = PrivateNodes(alias)
131+
return nil
132+
}
133+
121134
type CloudControllerManager struct {
122135
// Enabled defines if the embedded cloud controller manager should be enabled. This defaults to true, but can be disabled if you want to use
123136
// an external cloud controller manager such as AWS or GCP. The cloud controller manager is responsible for setting the node's ip addresses as well

pkg/cli/delete_helm.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"errors"
66
"fmt"
77
"os/exec"
8+
"strings"
89
"time"
910

1011
"github.com/ghodss/yaml"
@@ -130,7 +131,15 @@ func DeleteHelm(ctx context.Context, platformClient platform.Client, options *De
130131
vclusterConfig := &config.Config{}
131132
err = yaml.Unmarshal(values, vclusterConfig)
132133
if err != nil {
133-
return err
134+
privateNodesError := errors.Is(err, config.ErrInvalidPrivateNodesConfig) ||
135+
strings.Contains(err.Error(), config.ErrInvalidPrivateNodesConfig.Error())
136+
if privateNodesError {
137+
cmd.log.Warnf("Failed to parse vcluster config from Helm values: %v. ", err)
138+
cmd.log.Infof("Continuing with deletion...")
139+
vclusterConfig = nil
140+
} else {
141+
return fmt.Errorf("failed to parse vcluster config from Helm values: %w", err)
142+
}
134143
}
135144

136145
// we have to delete the chart
@@ -203,7 +212,7 @@ func DeleteHelm(ctx context.Context, platformClient platform.Client, options *De
203212
}
204213

205214
// if namespace sync is enabled, use cleanup handlers to handle namespace cleanup
206-
if vclusterConfig.Sync.ToHost.Namespaces.Enabled {
215+
if vclusterConfig != nil && vclusterConfig.Sync.ToHost.Namespaces.Enabled {
207216
if err := CleanupSyncedNamespaces(ctx, cmd.Namespace, vClusterName, cmd.restConfig, cmd.kubeClient, cmd.log); err != nil {
208217
return fmt.Errorf("run namespace cleanup: %w", err)
209218
}

0 commit comments

Comments
 (0)