Skip to content
This repository has been archived by the owner on Jan 11, 2023. It is now read-only.

Commit

Permalink
Validation for WindowsProfile (#2798)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
JamesEarle authored and Cecile Robert-Michon committed May 17, 2018
1 parent 36fac61 commit 388f58f
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions pkg/api/vlabs/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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)")
}
}
}
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 388f58f

Please sign in to comment.