github.com/SUSE/skuba@v1.4.17/pkg/skuba/actions/validate/validate.go (about) 1 /* 2 * Copyright (c) 2019 SUSE LLC. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 * 16 */ 17 18 package validate 19 20 import ( 21 "fmt" 22 "regexp" 23 24 "github.com/SUSE/skuba/pkg/skuba" 25 ) 26 27 var nodeNameRegex = regexp.MustCompile(`^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$`) 28 29 // NodeName checks whether the node name is valid and acceptable for kubelet. 30 func NodeName(nodename string) error { 31 if len(nodename) > skuba.MaxNodeNameLength { 32 return fmt.Errorf( 33 "invalid node name \"%s\": must be no more than %d characters", 34 nodename, skuba.MaxNodeNameLength) 35 } 36 37 if !nodeNameRegex.MatchString(nodename) { 38 return fmt.Errorf( 39 "invalid node name \"%s\": must consist of lower case alphanumeric characters, '-' or '.', and must start and end with an alphanumeric character", 40 nodename) 41 } 42 return nil 43 }