Skip to content

Commit

Permalink
fix: kbcli cluster expose error (#384)
Browse files Browse the repository at this point in the history
  • Loading branch information
iziang authored Jul 3, 2024
1 parent 30d12f4 commit a3f77a5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 20 deletions.
33 changes: 14 additions & 19 deletions pkg/cmd/cluster/operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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
}

Expand All @@ -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 == "" {
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion pkg/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a3f77a5

Please sign in to comment.