Skip to content

Commit

Permalink
No worker/verbosity config on watches yaml
Browse files Browse the repository at this point in the history
Prevent configuration of ansible verbosity or max worker from
watches.yaml
  • Loading branch information
djzager committed Aug 28, 2019
1 parent 411ac7d commit 3764e8c
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 263 deletions.
24 changes: 20 additions & 4 deletions pkg/ansible/watches/testdata/valid.yaml.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,27 @@
sentinel: finalizer_running
- version: v1alpha1
group: app.example.com
kind: MaxWorkers
kind: MaxWorkersDefault
role: {{ .ValidRole }}
maxWorkers: 3
- version: v1alpha1
group: app.example.com
kind: AnsibleVerbosity
kind: MaxWorkersIgnored
role: {{ .ValidRole }}
maxWorkers: 5
- version: v1alpha1
group: app.example.com
kind: MaxWorkersEnv
role: {{ .ValidRole }}
- version: v1alpha1
group: app.example.com
kind: AnsibleVerbosityDefault
role: {{ .ValidRole }}
- version: v1alpha1
group: app.example.com
kind: AnsibleVerbosityIgnored
role: {{ .ValidRole }}
ansibleVerbosity: 5
- version: v1alpha1
group: app.example.com
kind: AnsibleVerbosityEnv
role: {{ .ValidRole }}
ansibleVerbosity: 11
22 changes: 11 additions & 11 deletions pkg/ansible/watches/watches.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,15 @@ type Watch struct {
Playbook string `yaml:"playbook"`
Role string `yaml:"role"`
MaxRunnerArtifacts int `yaml:"maxRunnerArtifacts"`
MaxWorkers int `yaml:"maxWorkers"`
ReconcilePeriod time.Duration `yaml:"reconcilePeriod"`
ManageStatus bool `yaml:"manageStatus"`
WatchDependentResources bool `yaml:"watchDependentResources"`
WatchClusterScopedResources bool `yaml:"watchClusterScopedResources"`
AnsibleVerbosity int `yaml:"ansibleVerbosity"`
Finalizer *Finalizer `yaml:"finalizer"`

// Not configurable via watches.yaml
MaxWorkers int `yaml:"maxWorkers"`
AnsibleVerbosity int `yaml:"ansibleVerbosity"`
}

// Finalizer - Expose finalizer to be used by a user.
Expand All @@ -60,12 +62,14 @@ type Finalizer struct {
// Default values for optional fields on Watch
var (
maxRunnerArtifactsDefault = 20
maxWorkersDefault = 1 //set by flags
reconcilePeriodDefault = "0s"
manageStatusDefault = true
watchDependentResourcesDefault = true
watchClusterScopedResourcesDefault = false
ansibleVerbosityDefault = 2 //set by flags

// these are overridden by cmdline flags
maxWorkersDefault = 1
ansibleVerbosityDefault = 2
)

// UnmarshalYAML - implements the yaml.Unmarshaler interface for Watch
Expand All @@ -78,25 +82,21 @@ func (w *Watch) UnmarshalYAML(unmarshal func(interface{}) error) error {
Playbook string `yaml:"playbook"`
Role string `yaml:"role"`
MaxRunnerArtifacts int `yaml:"maxRunnerArtifacts"`
MaxWorkers int `yaml:"maxWorkers"`
ReconcilePeriod string `yaml:"reconcilePeriod"`
ManageStatus bool `yaml:"manageStatus"`
WatchDependentResources bool `yaml:"watchDependentResources"`
WatchClusterScopedResources bool `yaml:"watchClusterScopedResources"`
AnsibleVerbosity int `yaml:"ansibleVerbosity"`
Finalizer *Finalizer `yaml:"finalizer"`
}
var tmp alias

// by default, the operator will manage status and watch dependent resources
// The operator will not manage cluster scoped resources by default.
tmp.ManageStatus = manageStatusDefault
// the operator will not manage cluster scoped resources by default.
tmp.WatchDependentResources = watchDependentResourcesDefault
tmp.MaxRunnerArtifacts = maxRunnerArtifactsDefault
tmp.MaxWorkers = maxWorkersDefault
tmp.ReconcilePeriod = reconcilePeriodDefault
tmp.WatchClusterScopedResources = watchClusterScopedResourcesDefault
tmp.AnsibleVerbosity = ansibleVerbosityDefault

if err := unmarshal(&tmp); err != nil {
return err
Expand All @@ -122,13 +122,13 @@ func (w *Watch) UnmarshalYAML(unmarshal func(interface{}) error) error {
w.Playbook = tmp.Playbook
w.Role = tmp.Role
w.MaxRunnerArtifacts = tmp.MaxRunnerArtifacts
w.MaxWorkers = getMaxWorkers(gvk, tmp.MaxWorkers)
w.MaxWorkers = getMaxWorkers(gvk, maxWorkersDefault)
w.ReconcilePeriod = reconcilePeriod
w.ManageStatus = tmp.ManageStatus
w.WatchDependentResources = tmp.WatchDependentResources
w.WatchClusterScopedResources = tmp.WatchClusterScopedResources
w.Finalizer = tmp.Finalizer
w.AnsibleVerbosity = getAnsibleVerbosity(gvk, tmp.AnsibleVerbosity)
w.AnsibleVerbosity = getAnsibleVerbosity(gvk, ansibleVerbosityDefault)

return nil
}
Expand Down
Loading

0 comments on commit 3764e8c

Please sign in to comment.