Skip to content

Commit

Permalink
Adjusts A5/A6 configuration conversion sequence (#4813)
Browse files Browse the repository at this point in the history
  • Loading branch information
prognant authored May 13, 2020
1 parent b4f2c81 commit 8ef20b4
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 47 deletions.
60 changes: 30 additions & 30 deletions cmd/agent/common/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,36 +70,6 @@ func ImportConfig(oldConfigDir string, newConfigDir string, force bool) error {
return fmt.Errorf("unable to convert configuration data from %s: %v", datadogConfPath, err)
}

// backup the original datadog.yaml to datadog.yaml.bak
if !created {
err = os.Rename(datadogYamlPath, datadogYamlPath+".bak")
if err != nil {
return fmt.Errorf("unable to create a backup for the existing file: %s", datadogYamlPath)
}
}

// marshal the config object to YAML
b, err := yaml.Marshal(config.Datadog.AllSettings())
if err != nil {
return fmt.Errorf("unable to marshal config to YAML: %v", err)
}

// dump the current configuration to datadog.yaml
// file permissions will be used only to create the file if doesn't exist,
// please note on Windows such permissions have no effect.
if err = ioutil.WriteFile(datadogYamlPath, b, 0640); err != nil {
return fmt.Errorf("unable to write config to %s: %v", datadogYamlPath, err)
}

fmt.Fprintln(
color.Output,
fmt.Sprintf("%s imported the contents of %s into %s",
color.GreenString("Success:"),
datadogConfPath,
datadogYamlPath,
),
)

// move existing config files to the new configuration directory
files, err := ioutil.ReadDir(filepath.Join(oldConfigDir, "conf.d"))
if err != nil {
Expand Down Expand Up @@ -158,6 +128,36 @@ func ImportConfig(oldConfigDir string, newConfigDir string, force bool) error {
)
}

// backup the original datadog.yaml to datadog.yaml.bak
if !created {
err = os.Rename(datadogYamlPath, datadogYamlPath+".bak")
if err != nil {
return fmt.Errorf("unable to create a backup for the existing file: %s", datadogYamlPath)
}
}

// marshal the config object to YAML
b, err := yaml.Marshal(config.Datadog.AllSettings())
if err != nil {
return fmt.Errorf("unable to marshal config to YAML: %v", err)
}

// dump the current configuration to datadog.yaml
// file permissions will be used only to create the file if doesn't exist,
// please note on Windows such permissions have no effect.
if err = ioutil.WriteFile(datadogYamlPath, b, 0640); err != nil {
return fmt.Errorf("unable to write config to %s: %v", datadogYamlPath, err)
}

fmt.Fprintln(
color.Output,
fmt.Sprintf("%s imported the contents of %s into %s",
color.GreenString("Success:"),
datadogConfPath,
datadogYamlPath,
),
)

// move existing config templates to the new auto_conf directory
autoConfFiles, err := ioutil.ReadDir(filepath.Join(oldConfigDir, "conf.d", "auto_conf"))
if err != nil {
Expand Down
32 changes: 15 additions & 17 deletions pkg/config/legacy/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,54 +140,52 @@ func importKubernetesConfWithDeprec(src, dst string, overwrite bool) (kubeDeprec
return deprecations, fmt.Errorf("Could not Unmarshal instances from %s: %s", src, err)
}

configConverter := config.NewConfigConverter()

if instance.KubeletPort > 0 {
configConverter.Set("kubernetes_http_kubelet_port", instance.KubeletPort)
configConverter.Set("kubernetes_https_kubelet_port", instance.KubeletPort)
config.Datadog.Set("kubernetes_http_kubelet_port", instance.KubeletPort)
config.Datadog.Set("kubernetes_https_kubelet_port", instance.KubeletPort)
}
if len(instance.KubeletHost) > 0 {
configConverter.Set("kubernetes_kubelet_host", instance.KubeletHost)
config.Datadog.Set("kubernetes_kubelet_host", instance.KubeletHost)
}
if len(instance.KubeletClientCrt) > 0 {
configConverter.Set("kubelet_client_crt", instance.KubeletClientCrt)
config.Datadog.Set("kubelet_client_crt", instance.KubeletClientCrt)
}
if len(instance.KubeletClientKey) > 0 {
configConverter.Set("kubelet_client_key", instance.KubeletClientKey)
config.Datadog.Set("kubelet_client_key", instance.KubeletClientKey)
}
if len(instance.KubeletCACert) > 0 {
configConverter.Set("kubelet_client_ca", instance.KubeletCACert)
config.Datadog.Set("kubelet_client_ca", instance.KubeletCACert)
}
if len(instance.KubeletTokenPath) > 0 {
configConverter.Set("kubelet_auth_token_path", instance.KubeletTokenPath)
config.Datadog.Set("kubelet_auth_token_path", instance.KubeletTokenPath)
}
if len(instance.NodeLabelsToTags) > 0 {
configConverter.Set("kubernetes_node_labels_as_tags", instance.NodeLabelsToTags)
config.Datadog.Set("kubernetes_node_labels_as_tags", instance.NodeLabelsToTags)
}

// We need to verify the kubelet_tls_verify is actually present before
// changing the secure `true` default
if verify, err := strconv.ParseBool(instance.KubeletTLSVerify); err == nil {
configConverter.Set("kubelet_tls_verify", verify)
config.Datadog.Set("kubelet_tls_verify", verify)
}

// Implicit default in Agent5 was true
if verify, err := strconv.ParseBool(instance.CollectServiceTags); err == nil {
configConverter.Set("kubernetes_collect_service_tags", verify)
config.Datadog.Set("kubernetes_collect_service_tags", verify)
} else {
configConverter.Set("kubernetes_collect_service_tags", true)
config.Datadog.Set("kubernetes_collect_service_tags", true)
}

// Temporarily in main datadog.yaml, will move to DCA
// Booleans are always imported as zero value is false
configConverter.Set("collect_kubernetes_events", instance.CollectEvents)
configConverter.Set("leader_election", instance.LeaderCandidate)
config.Datadog.Set("collect_kubernetes_events", instance.CollectEvents)
config.Datadog.Set("leader_election", instance.LeaderCandidate)

if instance.LeaderLeaseDuration > 0 {
configConverter.Set("leader_lease_duration", instance.LeaderLeaseDuration)
config.Datadog.Set("leader_lease_duration", instance.LeaderLeaseDuration)
}
if instance.ServiceTagUpdateTag > 0 {
configConverter.Set("kubernetes_service_tag_update_freq", instance.ServiceTagUpdateTag)
config.Datadog.Set("kubernetes_service_tag_update_freq", instance.ServiceTagUpdateTag)
}

// Deprecations
Expand Down

0 comments on commit 8ef20b4

Please sign in to comment.