Add addon-overwrite flag (#4377)

provide a `addon-overwrite` flag for upgrades to skip `linkerd-config-addons` and use `--addon-overwrite` if passed or defaults
This commit is contained in:
Tarun Pothulapati 2020-05-21 15:31:41 +00:00 committed by GitHub
parent 3473db32f8
commit bd60c90e5d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 6858 additions and 22 deletions

View File

@ -554,7 +554,7 @@ func (options *installOptions) allStageFlagSet() *pflag.FlagSet {
flags.StringVar(
&options.addOnConfig, "addon-config", options.addOnConfig,
"A path to a configuration file of add-ons",
"A path to a configuration file of add-ons. If add-on config already exists, this new config gets merged with the existing one (unless --addon-overwrite is used)",
)
return flags
@ -647,7 +647,7 @@ func (options *installOptions) recordFlags(flags *pflag.FlagSet) {
flags.VisitAll(func(f *pflag.Flag) {
if f.Changed {
switch f.Name {
case "ignore-cluster", "control-plane-version", "proxy-version", "identity-issuer-certificate-file", "identity-issuer-key-file", "identity-trust-anchors-file":
case "ignore-cluster", "control-plane-version", "proxy-version", "identity-issuer-certificate-file", "identity-issuer-key-file", "identity-trust-anchors-file", "addon-config":
// These flags don't make sense to record.
default:
options.recordedFlags = append(options.recordedFlags, &pb.Install_Flag{

View File

@ -21,6 +21,14 @@ func TestAddOnRender(t *testing.T) {
withTracingAddonValues.Tracing["enabled"] = true
addFakeTLSSecrets(withTracingAddonValues)
withTracingOverwrite, err := testInstallOptions()
if err != nil {
t.Fatalf("Unexpected error: %v\n", err)
}
withTracingOverwrite.addOnConfig = filepath.Join("testdata", "addon_config_overwrite.yaml")
withTracingOverwriteValues, _, _ := withTracingOverwrite.validateAndBuild("", nil)
addFakeTLSSecrets(withTracingOverwriteValues)
withExistingGrafana, err := testInstallOptions()
if err != nil {
t.Fatalf("Unexpected error: %v\n", err)
@ -28,11 +36,13 @@ func TestAddOnRender(t *testing.T) {
withExistingGrafana.addOnConfig = filepath.Join("testdata", "existing-grafana-config.yaml")
withExistingGrafanaValues, _, _ := withExistingGrafana.validateAndBuild("", nil)
addFakeTLSSecrets(withExistingGrafanaValues)
testCases := []struct {
values *charts.Values
goldenFileName string
}{
{withTracingAddonValues, "install_tracing.golden"},
{withTracingOverwriteValues, "install_tracing_overwrite.golden"},
{withExistingGrafanaValues, "install_grafana_existing.golden"},
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -33,8 +33,9 @@ const (
)
type upgradeOptions struct {
manifests string
force bool
addOnOverwrite bool
manifests string
force bool
*installOptions
verifyTLS func(tls *charts.TLS, service string) error
@ -67,7 +68,10 @@ func (options *upgradeOptions) upgradeOnlyFlagSet() *pflag.FlagSet {
&options.force, "force", options.force,
"Force upgrade operation even when issuer certificate does not work with the trust anchors of all proxies",
)
flags.BoolVar(
&options.addOnOverwrite, "addon-overwrite", options.addOnOverwrite,
"Overwrite (instead of merge) existing add-ons config with file in --addon-config (or reset to defaults if no new config is passed)",
)
return flags
}
@ -346,25 +350,29 @@ func (options *upgradeOptions) validateAndBuild(stage string, k kubernetes.Inter
values.Stage = stage
// Update Add-Ons Configuration from the linkerd-value cm
cmRawValues, _ := k8s.GetAddOnsConfigMap(k, controlPlaneNamespace)
if !options.addOnOverwrite {
// Update Add-Ons Configuration from the linkerd-value cm
cmRawValues, _ := k8s.GetAddOnsConfigMap(k, controlPlaneNamespace)
if cmRawValues != nil {
//Cm is present now get the data
cmData, ok := cmRawValues["values"]
if !ok {
return nil, nil, fmt.Errorf("values subpath not found in %s configmap", k8s.AddOnsConfigMapName)
}
rawValues, err := yaml.Marshal(values)
if err != nil {
return nil, nil, err
}
if cmRawValues != nil {
//Cm is present now get the data
cmData := cmRawValues["values"]
rawValues, err := yaml.Marshal(values)
if err != nil {
return nil, nil, err
}
// over-write add-on values with cmValues
// Merge Add-On Values with Values
if rawValues, err = mergeRaw(rawValues, []byte(cmData)); err != nil {
return nil, nil, err
}
// over-write add-on values with cmValues
// Merge Add-On Values with Values
if rawValues, err = mergeRaw(rawValues, []byte(cmData)); err != nil {
return nil, nil, err
}
if err = yaml.Unmarshal(rawValues, &values); err != nil {
return nil, nil, err
if err = yaml.Unmarshal(rawValues, &values); err != nil {
return nil, nil, err
}
}
}

View File

@ -1925,6 +1925,38 @@ data:
options.addOnConfig = filepath.Join("testdata", "grafana_disabled.yaml")
},
},
{
// Linkerd upgrade with addons-overwrite
k8sConfigs: append(commonk8sconfig, `
kind: ConfigMap
apiVersion: v1
metadata:
name: linkerd-config-addons
namespace: linkerd
labels:
linkerd.io/control-plane-ns: linkerd
annotations:
linkerd.io/created-by: linkerd/cli edge-19.4.1
data:
values: |-
grafana:
enabled: true
resources:
cpu:
limit: "1"
request: 100m
memory:
limit: 250Mi
request: 50Mi
`),
outputfile: "upgrade_grafana_addon_overwrite.yaml",
err: nil,
processOptions: func(options *upgradeOptions) {
options.addOnConfig = filepath.Join("testdata", "grafana_enabled.yaml")
options.addOnOverwrite = true
},
},
}
for i, tc := range testCases {
tc := tc // pin