diff --git a/pkg/cmd/cluster/operations.go b/pkg/cmd/cluster/operations.go index 45a341db3..b66ae46d0 100755 --- a/pkg/cmd/cluster/operations.go +++ b/pkg/cmd/cluster/operations.go @@ -613,12 +613,10 @@ func (o *OperationsOptions) validateExpose() error { return fmt.Errorf("invalid expose type %q", o.ExposeType) } - if o.ExposeSubType != "" { - switch o.ExposeSubType { - case "", util.LoadBalancer, util.NodePort: - default: - return fmt.Errorf("invalid expose subtype %q", o.ExposeSubType) - } + switch o.ExposeSubType { + case util.LoadBalancer, util.NodePort: + default: + return fmt.Errorf("invalid expose subtype %q", o.ExposeSubType) } switch strings.ToLower(o.ExposeEnabled) { @@ -627,10 +625,6 @@ func (o *OperationsOptions) validateExpose() error { return fmt.Errorf("invalid value for enable flag: %s", o.ExposeEnabled) } - if util.ExposeType(o.ExposeType) == util.ExposeToInternet && o.ExposeSubType != "" { - return fmt.Errorf("expose subtype is not supported for expose to internet") - } - return nil } @@ -644,6 +638,14 @@ func (o *OperationsOptions) fillExpose() error { return err } + if len(o.ComponentNames) == 0 { + return fmt.Errorf("there are multiple components in cluster, please use --components to specify the component for expose") + } + if len(o.ComponentNames) > 1 { + return fmt.Errorf("only one component can be exposed at a time") + } + componentName := o.ComponentNames[0] + // default expose to internet exposeType := util.ExposeType(o.ExposeType) if exposeType == "" { @@ -655,22 +657,15 @@ func (o *OperationsOptions) fillExpose() error { return err } - if o.Component == "" { - if len(clusterObj.Spec.ComponentSpecs) > 1 { - return fmt.Errorf("there are multiple components in cluster, please use --component to specify the component for promote") - } - o.Component = clusterObj.Spec.ComponentSpecs[0].Name - } - var componentSpec *appsv1alpha1.ClusterComponentSpec for _, compSpec := range clusterObj.Spec.ComponentSpecs { - if compSpec.Name == o.Component { + if compSpec.Name == componentName { componentSpec = &compSpec break } } if componentSpec == nil { - return fmt.Errorf("component %s not found", o.Component) + return fmt.Errorf("component %s not found", componentName) } annotations, err := util.GetExposeAnnotations(provider, exposeType) diff --git a/pkg/util/util.go b/pkg/util/util.go index f51c00d69..136c4428a 100644 --- a/pkg/util/util.go +++ b/pkg/util/util.go @@ -622,7 +622,7 @@ func GetCompDefByName(cli dynamic.Interface, compDefName string) (*appsv1alpha1. Namespace: "", Name: compDefName, } - if err := GetResourceObjectFromGVR(types.ClusterDefGVR(), compDefKey, cli, &compDef); err != nil { + if err := GetResourceObjectFromGVR(types.CompDefGVR(), compDefKey, cli, &compDef); err != nil { return nil, err } return compDef, nil