Skip to content

Commit

Permalink
Fix build
Browse files Browse the repository at this point in the history
Signed-off-by: Tamal Saha <tamal@appscode.com>
  • Loading branch information
tamalsaha committed Oct 7, 2020
1 parent c97abe0 commit a71f9b7
Showing 1 changed file with 9 additions and 16 deletions.
25 changes: 9 additions & 16 deletions pkg/validator/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package validator

import (
"context"
"encoding/json"
"fmt"
"strings"

Expand Down Expand Up @@ -68,27 +67,21 @@ func ValidateStorage(client kubernetes.Interface, storageType api.StorageType, s
}

// ValidateMonitorSpec validates the Monitoring spec after all the defaulting is done.
func ValidateMonitorSpec(monitorSpec *mona.AgentSpec) error {
specData, err := json.Marshal(monitorSpec)
if err != nil {
return err
func ValidateMonitorSpec(agent *mona.AgentSpec) error {
if agent.Agent == "" {
return fmt.Errorf(`object 'Agent' is missing in '%+v'`, agent)
}

if monitorSpec.Agent == "" {
return fmt.Errorf(`object 'Agent' is missing in '%v'`, string(specData))
}

if monitorSpec.Agent.Vendor() == mona.VendorPrometheus {
if monitorSpec.Prometheus != nil &&
monitorSpec.Prometheus.Exporter != nil &&
monitorSpec.Prometheus.Exporter.Port >= 1024 &&
monitorSpec.Prometheus.Exporter.Port <= 65535 {
if agent.Agent.Vendor() == mona.VendorPrometheus {
if agent.Prometheus != nil &&
agent.Prometheus.Exporter.Port >= 1024 &&
agent.Prometheus.Exporter.Port <= 65535 {
return nil
}
return fmt.Errorf(`invalid 'Monitor.Prometheus' in '%v'. prometheus.exporter.port value must be between 1024 and 65535, inclusive`, string(specData))
return fmt.Errorf(`invalid 'monitor.prometheus' in '%+v'. prometheus.exporter.port value must be between 1024 and 65535, inclusive`, agent)
}

return fmt.Errorf(`invalid 'Agent' in '%v'`, string(specData))
return fmt.Errorf(`invalid 'Agent' in '%+v'`, agent)
}

func ValidateEnvVar(envs []core.EnvVar, forbiddenEnvs []string, resourceType string) error {
Expand Down

0 comments on commit a71f9b7

Please sign in to comment.