Skip to content

Commit

Permalink
fix: add a kusion-control label in svc labels and allow empty ports i…
Browse files Browse the repository at this point in the history
…n a Service (#510)
  • Loading branch information
SparkYuan authored Sep 7, 2023
1 parent ef0cb37 commit 3bfeff3
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,17 @@ const (
suffixPublic = "public"
suffixPrivate = "private"

// aliyun SLB annotations, ref: https://help.aliyun.com/zh/ack/ack-managed-and-ack-dedicated/user-guide/add-annotations-to-the-yaml-file-of-a-service-to-configure-clb-instances?spm=a2c4g.11186623.0.0.59e26219ESUbqe
// aliyun SLB annotations, ref: https://help.aliyun.com/zh/ack/ack-managed-and-ack-dedicated/user-guide/add-annotations-to-the-yaml-file-of-a-service-to-configure-clb-instances
aliyunLBSpec = "service.beta.kubernetes.io/alibaba-cloud-loadbalancer-spec"
aliyunSLBS1Small = "slb.s1.small"
kusionControl = "kusionstack.io/control"
)

var (
ErrEmptyAppName = errors.New("app name must not be empty")
ErrEmptyProjectName = errors.New("project name must not be empty")
ErrEmptyStackName = errors.New("stack name must not be empty")
ErrEmptySelectors = errors.New("selectors must not be empty")
ErrEmptyPorts = errors.New("ports must not be empty")
ErrInvalidPort = errors.New("port must be between 1 and 65535")
ErrInvalidTargetPort = errors.New("targetPort must be between 1 and 65535 if exist")
ErrInvalidProtocol = errors.New("protocol must be TCP or UDP")
Expand Down Expand Up @@ -163,16 +163,13 @@ func (g *portsGenerator) generateK8sSvc(public bool, ports []network.Port) *v1.S

// only support Aliyun SLB for now, and set SLB spec by default.
svc.Annotations[aliyunLBSpec] = aliyunSLBS1Small
svc.Labels[kusionControl] = "true"
}

return svc
}

func validatePorts(ports []network.Port) error {
if len(ports) == 0 {
return ErrEmptyPorts
}

portProtocolRecord := make(map[string]struct{})
for _, port := range ports {
if err := validatePort(&port); err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,8 @@ func TestPortsGenerator_Generate(t *testing.T) {
Name: "testProject-testStack-testApp-public",
Namespace: "testProject",
Labels: map[string]string{
"test-l-key": "test-l-value",
"test-l-key": "test-l-value",
kusionControl: "true",
},
Annotations: map[string]string{
"test-a-key": "test-a-value",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

"github.com/stretchr/testify/require"
"gopkg.in/yaml.v3"

"kusionstack.io/kusion/pkg/models"
"kusionstack.io/kusion/pkg/models/appconfiguration/workload"
"kusionstack.io/kusion/pkg/models/appconfiguration/workload/container"
Expand All @@ -31,6 +32,7 @@ metadata:
labels:
app.kubernetes.io/name: foo
app.kubernetes.io/part-of: default
kusionstack.io/control: "true"
name: default-dev-foo-public
namespace: default
spec:
Expand Down

0 comments on commit 3bfeff3

Please sign in to comment.