From 388f58fb027c5386736b035804902ad5347187e1 Mon Sep 17 00:00:00 2001 From: James Earle Date: Wed, 16 May 2018 18:16:07 -0700 Subject: [PATCH] Validation for WindowsProfile (#2798) * adding windowsprofile validation checking, will handle 'hassecrets' error in generation #2788 * adding null check for windows profile before validation * adding ostype check and validation * check for empty string not nil * change string to ostype in validatePoolOSType * removing redundant windows check, using constants for validation * empty string as valid option * syntax fix --- pkg/api/vlabs/validate.go | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/pkg/api/vlabs/validate.go b/pkg/api/vlabs/validate.go index dd12e31f63..ceb3bb40a9 100644 --- a/pkg/api/vlabs/validate.go +++ b/pkg/api/vlabs/validate.go @@ -305,6 +305,10 @@ func (a *AgentPoolProfile) Validate(orchestratorType string) error { return e } + if e := validatePoolOSType(a.OSType); e != nil { + return e + } + // for Kubernetes, we don't support AgentPoolProfile.DNSPrefix if orchestratorType == Kubernetes { if e := validate.Var(a.DNSPrefix, "len=0"); e != nil { @@ -645,9 +649,6 @@ func (a *Properties) Validate(isUpdate bool) error { } if agentPoolProfile.OSType == Windows { - if e := validate.Var(a.WindowsProfile, "required"); e != nil { - return fmt.Errorf("WindowsProfile must not be empty since agent pool '%s' specifies windows", agentPoolProfile.Name) - } switch a.OrchestratorProfile.OrchestratorType { case DCOS: case Swarm: @@ -676,8 +677,12 @@ func (a *Properties) Validate(isUpdate bool) error { default: return fmt.Errorf("Orchestrator %s does not support Windows", a.OrchestratorProfile.OrchestratorType) } - if e := a.WindowsProfile.Validate(); e != nil { - return e + if a.WindowsProfile != nil { + if e := a.WindowsProfile.Validate(); e != nil { + return e + } + } else { + return fmt.Errorf("WindowsProfile is required when the cluster definition contains Windows agent pool(s)") } } } @@ -1037,6 +1042,13 @@ func validatePoolName(poolName string) error { return nil } +func validatePoolOSType(os OSType) error { + if os != Linux && os != Windows && os != "" { + return fmt.Errorf("AgentPoolProfile.osType must be either Linux or Windows") + } + return nil +} + func validateDNSName(dnsName string) error { dnsNameRegex := `^([A-Za-z][A-Za-z0-9-]{1,43}[A-Za-z0-9])$` re, err := regexp.Compile(dnsNameRegex)