Skip to content

Commit

Permalink
Customize leader-election config map error checks
Browse files Browse the repository at this point in the history
  • Loading branch information
LorcanMcVeigh authored Sep 13, 2019
1 parent 4e5e67f commit a560a15
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions cmd/nginx-ingress/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"github.com/prometheus/client_golang/prometheus"
api_v1 "k8s.io/api/core/v1"
meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/validation"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/kubernetes/scheme"
"k8s.io/client-go/rest"
Expand Down Expand Up @@ -137,6 +138,11 @@ func main() {
os.Exit(0)
}

statusLockNameValidationError := validateResourceName(*leaderElectionLockName)
if statusLockNameValidationError != nil {
glog.Fatalf("Invalid value for leader-election-lock-name: %v", statusLockNameValidationError)
}

statusPortValidationError := validatePort(*nginxStatusPort)
if statusPortValidationError != nil {
glog.Fatalf("Invalid value for nginx-status-port: %v", statusPortValidationError)
Expand Down Expand Up @@ -445,6 +451,15 @@ func getSocketClient(sockPath string) *http.Client {
}
}

// validateResourceName validates the name of a resource
func validateResourceName(lock string) error {
allErrs := validation.IsDNS1123Subdomain(lock)
if len(allErrs) > 0 {
return fmt.Errorf("invalid resource name %v: %v", lock, allErrs)
}
return nil
}

// validatePort makes sure a given port is inside the valid port range for its usage
func validatePort(port int) error {
if port < 1023 || port > 65535 {
Expand Down

0 comments on commit a560a15

Please sign in to comment.