Skip to content

Commit

Permalink
Merge pull request #540 from replicatedhq/divolgin/ns
Browse files Browse the repository at this point in the history
Apply templates to troubleshoot spec
  • Loading branch information
divolgin committed May 14, 2020
2 parents f7e6088 + e435955 commit f5a74c9
Showing 1 changed file with 20 additions and 15 deletions.
35 changes: 20 additions & 15 deletions kotsadm/pkg/handlers/troubleshoot.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"github.com/replicatedhq/kots/kotsadm/pkg/session"
"github.com/replicatedhq/kots/kotsadm/pkg/supportbundle"
"github.com/replicatedhq/kots/kotsadm/pkg/version"
"github.com/replicatedhq/kots/pkg/template"
troubleshootanalyze "github.com/replicatedhq/troubleshoot/pkg/analyze"
"github.com/replicatedhq/troubleshoot/pkg/apis/troubleshoot/v1beta1"
troubleshootv1beta1 "github.com/replicatedhq/troubleshoot/pkg/apis/troubleshoot/v1beta1"
Expand Down Expand Up @@ -359,32 +360,36 @@ func populateNamespaces(existingSpec *v1beta1.Collector) *v1beta1.Collector {
return existingSpec
}

builder := template.Builder{}
builder.AddCtx(template.StaticCtx{})

ns := func(ns string) string {
templated, err := builder.RenderTemplate("ns", ns)
if err != nil {
logger.Error(err)
}
if templated != "" {
return templated
}
return os.Getenv("POD_NAMESPACE")
}

collects := []*v1beta1.Collect{}
for _, collect := range existingSpec.Spec.Collectors {
if collect.Secret != nil {
if collect.Secret.Namespace == "" {
collect.Secret.Namespace = os.Getenv("POD_NAMESPACE")
}
collect.Secret.Namespace = ns(collect.Secret.Namespace)
}
if collect.Run != nil {
if collect.Run.Namespace == "" {
collect.Run.Namespace = os.Getenv("POD_NAMESPACE")
}
collect.Run.Namespace = ns(collect.Run.Namespace)
}
if collect.Logs != nil {
if collect.Logs.Namespace == "" {
collect.Logs.Namespace = os.Getenv("POD_NAMESPACE")
}
collect.Logs.Namespace = ns(collect.Logs.Namespace)
}
if collect.Exec != nil {
if collect.Exec.Namespace == "" {
collect.Exec.Namespace = os.Getenv("POD_NAMESPACE")
}
collect.Exec.Namespace = ns(collect.Exec.Namespace)
}
if collect.Copy != nil {
if collect.Copy.Namespace == "" {
collect.Copy.Namespace = os.Getenv("POD_NAMESPACE")
}
collect.Copy.Namespace = ns(collect.Copy.Namespace)
}
collects = append(collects, collect)
}
Expand Down

0 comments on commit f5a74c9

Please sign in to comment.