mirror of https://github.com/linkerd/linkerd2.git
upgrade: Do not require an 'install' config (#2618)
Previous control plane versions do not provide an 'install' config, so this field cannot be required. Now, missing empty are handled more gracefully; and upgrade repairs install configs with missing fields.
This commit is contained in:
parent
a21c7be9f5
commit
9051e4f12d
|
|
@ -9,6 +9,7 @@ import (
|
|||
"github.com/linkerd/linkerd2/pkg/config"
|
||||
"github.com/linkerd/linkerd2/pkg/k8s"
|
||||
"github.com/linkerd/linkerd2/pkg/tls"
|
||||
"github.com/linkerd/linkerd2/pkg/version"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/pflag"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
|
|
@ -51,6 +52,10 @@ install command.`,
|
|||
return fmt.Errorf("could not fetch configs from kubernetes: %s", err)
|
||||
}
|
||||
|
||||
// If the install config needs to be repaired--either because it did not
|
||||
// exist or because it is missing expected fields, repair it.
|
||||
options.repairInstall(configs.Install)
|
||||
|
||||
// We recorded flags during a prior install. If we haven't overridden the
|
||||
// flag on this upgrade, reset that prior value as if it were specified now.
|
||||
//
|
||||
|
|
@ -117,6 +122,21 @@ func (options *upgradeOptions) newK8s() (*kubernetes.Clientset, error) {
|
|||
return kubernetes.NewForConfig(c)
|
||||
}
|
||||
|
||||
func (options *upgradeOptions) repairInstall(install *pb.Install) {
|
||||
if install == nil {
|
||||
install = &pb.Install{}
|
||||
}
|
||||
|
||||
if install.GetUuid() == "" {
|
||||
install.Uuid = options.generateUUID()
|
||||
}
|
||||
|
||||
// ALWAYS update the CLI version to the most recent.
|
||||
install.CliVersion = version.Version
|
||||
|
||||
// Install flags are updated separately.
|
||||
}
|
||||
|
||||
// fetchConfigs checks the kubernetes API to fetch an existing
|
||||
// linkerd configuration.
|
||||
//
|
||||
|
|
|
|||
|
|
@ -40,6 +40,12 @@ func unmarshalFile(filepath string, msg proto.Message) error {
|
|||
}
|
||||
|
||||
func unmarshal(json string, msg proto.Message) error {
|
||||
// If a config is missing, then just leave the message as nil and return
|
||||
// without an error.
|
||||
if json == "" {
|
||||
return nil
|
||||
}
|
||||
|
||||
// If we're using older code to read a newer config, blowing up during decoding
|
||||
// is not helpful. We should detect that through other means.
|
||||
u := jsonpb.Unmarshaler{AllowUnknownFields: true}
|
||||
|
|
@ -52,15 +58,15 @@ func FromConfigMap(configMap map[string]string) (*pb.All, error) {
|
|||
c := &pb.All{Global: &pb.Global{}, Proxy: &pb.Proxy{}, Install: &pb.Install{}}
|
||||
|
||||
if err := unmarshal(configMap["global"], c.Global); err != nil {
|
||||
return nil, fmt.Errorf("global: %s", err)
|
||||
return nil, fmt.Errorf("invlaid global config: %s", err)
|
||||
}
|
||||
|
||||
if err := unmarshal(configMap["proxy"], c.Proxy); err != nil {
|
||||
return nil, fmt.Errorf("proxy: %s", err)
|
||||
return nil, fmt.Errorf("invalid proxy config: %s", err)
|
||||
}
|
||||
|
||||
if err := unmarshal(configMap["install"], c.Install); err != nil {
|
||||
return nil, fmt.Errorf("install: %s", err)
|
||||
return nil, fmt.Errorf("invalid install config: %s", err)
|
||||
}
|
||||
|
||||
return c, nil
|
||||
|
|
|
|||
Loading…
Reference in New Issue