github.com/kubeshop/testkube@v1.17.23/cmd/kubectl-testkube/commands/common/validator/dns1123subdomain.go (about)

     1  package validator
     2  
     3  import (
     4  	"errors"
     5  	"fmt"
     6  
     7  	"github.com/spf13/cobra"
     8  	"k8s.io/apimachinery/pkg/util/validation"
     9  )
    10  
    11  func DNS1123Subdomain(cmd *cobra.Command, args []string) error {
    12  	if len(args) < 1 {
    13  		return errors.New("please pass valid resource name")
    14  	}
    15  
    16  	name := args[0]
    17  
    18  	errors := validation.IsDNS1123Subdomain(name)
    19  	if len(errors) > 0 {
    20  		return fmt.Errorf("invalid name, errors: %v", errors)
    21  	}
    22  
    23  	return nil
    24  }