Merge pull request #4224 from yuswift/validate-name

add validation for host cluster name
This commit is contained in:
KubeSphere CI Bot
2021-09-15 10:48:51 +08:00
committed by GitHub
2 changed files with 15 additions and 1 deletions

View File

@@ -139,6 +139,7 @@ func (s *KubeSphereControllerManagerOptions) Validate() []error {
errs = append(errs, s.OpenPitrixOptions.Validate()...)
errs = append(errs, s.NetworkOptions.Validate()...)
errs = append(errs, s.LdapOptions.Validate()...)
errs = append(errs, s.MultiClusterOptions.Validate()...)
if len(s.ApplicationSelector) != 0 {
_, err := labels.Parse(s.ApplicationSelector)

View File

@@ -17,9 +17,11 @@ limitations under the License.
package multicluster
import (
"errors"
"time"
"github.com/spf13/pflag"
"k8s.io/apimachinery/pkg/util/validation"
)
const (
@@ -67,7 +69,18 @@ func NewOptions() *Options {
}
func (o *Options) Validate() []error {
return nil
var err []error
res := validation.IsQualifiedName(o.HostClusterName)
if len(res) == 0 {
return err
}
err = append(err, errors.New("failed to create the host cluster because of invalid cluster name"))
for _, str := range res {
err = append(err, errors.New(str))
}
return err
}
func (o *Options) AddFlags(fs *pflag.FlagSet, s *Options) {