Skip to content

Commit a32bfce

Browse files
authored
feat: add custom configuration item (#552)
Signed-off-by: jyjiangkai <[email protected]>
1 parent 21da06a commit a32bfce

File tree

2 files changed

+135
-32
lines changed

2 files changed

+135
-32
lines changed

vsctl/command/cluster.go

Lines changed: 98 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,16 @@ type ClusterSpec struct {
7676
}
7777

7878
type Etcd struct {
79-
Replicas *int32 `yaml:"replicas"`
80-
StorageSize *string `yaml:"storage_size"`
81-
StorageClass *string `yaml:"storage_class"`
79+
Ports *EtcdPorts `yaml:"ports"`
80+
Replicas *int32 `yaml:"replicas"`
81+
StorageSize *string `yaml:"storage_size"`
82+
StorageClass *string `yaml:"storage_class"`
8283
}
8384

8485
type Controller struct {
85-
Replicas *int32 `yaml:"replicas"`
86+
Ports *ControllerPorts `yaml:"ports"`
87+
Replicas *int32 `yaml:"replicas"`
88+
SegmentCapacity *string `yaml:"segment_capacity"`
8689
}
8790

8891
type Store struct {
@@ -92,15 +95,45 @@ type Store struct {
9295
}
9396

9497
type Gateway struct {
95-
Replicas *int32 `yaml:"replicas"`
98+
Ports *GatewayPorts `yaml:"ports"`
99+
NodePorts *GatewayNodePorts `yaml:"nodeports"`
100+
Replicas *int32 `yaml:"replicas"`
96101
}
97102

98103
type Trigger struct {
99104
Replicas *int32 `yaml:"replicas"`
100105
}
101106

102107
type Timer struct {
103-
Replicas *int32 `yaml:"replicas"`
108+
Replicas *int32 `yaml:"replicas"`
109+
TimingWheel *TimingWheel `yaml:"timingwheel"`
110+
}
111+
112+
type EtcdPorts struct {
113+
Client *int32 `yaml:"client"`
114+
Peer *int32 `yaml:"peer"`
115+
}
116+
117+
type ControllerPorts struct {
118+
Controller *int32 `yaml:"controller"`
119+
RootController *int32 `yaml:"root_controller"`
120+
}
121+
122+
type GatewayPorts struct {
123+
Proxy *int32 `yaml:"proxy"`
124+
CloudEvents *int32 `yaml:"cloudevents"`
125+
SinkProxy *int32 `yaml:"sink_proxy"`
126+
}
127+
128+
type GatewayNodePorts struct {
129+
Proxy *int32 `yaml:"proxy"`
130+
CloudEvents *int32 `yaml:"cloudevents"`
131+
}
132+
133+
type TimingWheel struct {
134+
Tick *int32 `yaml:"tick"`
135+
Size *int32 `yaml:"wheel_size"`
136+
Layers *int32 `yaml:"layers"`
104137
}
105138

106139
func NewClusterCommand() *cobra.Command {
@@ -240,21 +273,9 @@ func createClusterCommand() *cobra.Command {
240273

241274
client := &http.Client{}
242275
url := fmt.Sprintf("%s%s%s/cluster", HttpPrefix, operatorEndpoint, BaseUrl)
243-
annotations := make(map[string]string)
244-
annotations[CoreComponentEtcdReplicasAnnotation] = fmt.Sprintf("%d", *c.Etcd.Replicas)
245-
annotations[CoreComponentEtcdStorageSizeAnnotation] = *c.Etcd.StorageSize
246-
if c.Etcd.StorageClass != nil {
247-
annotations[CoreComponentEtcdStorageClassAnnotation] = *c.Etcd.StorageClass
248-
}
249-
annotations[CoreComponentStoreReplicasAnnotation] = fmt.Sprintf("%d", *c.Store.Replicas)
250-
annotations[CoreComponentStoreStorageSizeAnnotation] = *c.Store.StorageSize
251-
if c.Store.StorageClass != nil {
252-
annotations[CoreComponentStoreStorageClassAnnotation] = *c.Store.StorageClass
253-
}
254-
annotations[CoreComponentTriggerReplicasAnnotation] = fmt.Sprintf("%d", *c.Trigger.Replicas)
255276
cluster := ClusterCreate{
256277
Version: *c.Version,
257-
Annotations: annotations,
278+
Annotations: genClusterAnnotations(c),
258279
}
259280
dataByte, err := json.Marshal(cluster)
260281
if err != nil {
@@ -768,27 +789,51 @@ func genClusterCommand() *cobra.Command {
768789
template := bytes.Buffer{}
769790
template.WriteString(fmt.Sprintf("version: %s\n", DefaultInitialVersion))
770791
template.WriteString("etcd:\n")
792+
template.WriteString(" # etcd service ports\n")
793+
template.WriteString(" ports:\n")
794+
template.WriteString(" client: 2379\n")
795+
template.WriteString(" peer: 2380\n")
771796
template.WriteString(" # etcd replicas is 3 by default, modification not supported\n")
772797
template.WriteString(" replicas: 3\n")
798+
template.WriteString(" # etcd storage size is 10Gi by default, supports both Gi and Mi units\n")
773799
template.WriteString(" storage_size: 10Gi\n")
774800
template.WriteString(" # specify the pvc storageclass of the etcd, use the cluster default storageclass by default\n")
775801
template.WriteString(" # storage_class: gp3\n")
776802
template.WriteString("controller:\n")
803+
template.WriteString(" # controller service ports\n")
804+
template.WriteString(" ports:\n")
805+
template.WriteString(" controller: 2048\n")
806+
template.WriteString(" root_controller: 2021\n")
777807
template.WriteString(" # controller replicas is 2 by default, modification not supported\n")
778808
template.WriteString(" replicas: 2\n")
809+
template.WriteString(" # segment capacity is 64Mi by default, supports both Gi and Mi units\n")
810+
template.WriteString(" segment_capacity: 64Mi\n")
779811
template.WriteString("store:\n")
780812
template.WriteString(" replicas: 3\n")
813+
template.WriteString(" # store storage size is 10Gi by default, supports both Gi and Mi units\n")
781814
template.WriteString(" storage_size: 10Gi\n")
782815
template.WriteString(" # specify the pvc storageclass of the store, use the cluster default storageclass by default\n")
783816
template.WriteString(" # storage_class: io2\n")
784817
template.WriteString("gateway:\n")
818+
template.WriteString(" # gateway service ports\n")
819+
template.WriteString(" # gateway.ports.cloudevents specify the cloudevents port, the default value is gateway.ports.proxy+1 and customization is not supported\n")
820+
template.WriteString(" ports:\n")
821+
template.WriteString(" proxy: 8080\n")
822+
template.WriteString(" cloudevents: 8081\n")
823+
template.WriteString(" nodeports:\n")
824+
template.WriteString(" proxy: 30001\n")
825+
template.WriteString(" cloudevents: 30002\n")
785826
template.WriteString(" # gateway replicas is 1 by default, modification not supported\n")
786827
template.WriteString(" replicas: 1\n")
787828
template.WriteString("trigger:\n")
788829
template.WriteString(" replicas: 1\n")
789830
template.WriteString("timer:\n")
790831
template.WriteString(" # timer replicas is 2 by default, modification not supported\n")
791832
template.WriteString(" replicas: 2\n")
833+
template.WriteString(" timingwheel:\n")
834+
template.WriteString(" tick: 1\n")
835+
template.WriteString(" wheel_size: 32\n")
836+
template.WriteString(" layers: 4\n")
792837
fileName := "cluster.yaml.example"
793838
err := ioutil.WriteFile(fileName, template.Bytes(), 0o644)
794839
if err != nil {
@@ -867,3 +912,37 @@ func getUpgradableVersionList(curVersion string) []string {
867912
func clusterIsVaild(c *ClusterSpec) bool {
868913
return c.Version != nil
869914
}
915+
916+
func genClusterAnnotations(c *ClusterSpec) map[string]string {
917+
annotations := make(map[string]string)
918+
// Etcd
919+
annotations[CoreComponentEtcdReplicasAnnotation] = fmt.Sprintf("%d", *c.Etcd.Replicas)
920+
annotations[CoreComponentEtcdStorageSizeAnnotation] = *c.Etcd.StorageSize
921+
annotations[CoreComponentEtcdPortClientAnnotation] = fmt.Sprintf("%d", *c.Etcd.Ports.Client)
922+
annotations[CoreComponentEtcdPortPeerAnnotation] = fmt.Sprintf("%d", *c.Etcd.Ports.Peer)
923+
if c.Etcd.StorageClass != nil {
924+
annotations[CoreComponentEtcdStorageClassAnnotation] = *c.Etcd.StorageClass
925+
}
926+
// Controller
927+
annotations[CoreComponentControllerSvcPortAnnotation] = fmt.Sprintf("%d", *c.Controller.Ports.Controller)
928+
annotations[CoreComponentRootControllerSvcPortAnnotation] = fmt.Sprintf("%d", *c.Controller.Ports.RootController)
929+
annotations[CoreComponentControllerSegmentCapacityAnnotation] = *c.Controller.SegmentCapacity
930+
// Store
931+
annotations[CoreComponentStoreReplicasAnnotation] = fmt.Sprintf("%d", *c.Store.Replicas)
932+
annotations[CoreComponentStoreStorageSizeAnnotation] = *c.Store.StorageSize
933+
if c.Store.StorageClass != nil {
934+
annotations[CoreComponentStoreStorageClassAnnotation] = *c.Store.StorageClass
935+
}
936+
// Gateway
937+
annotations[CoreComponentGatewayPortProxyAnnotation] = fmt.Sprintf("%d", *c.Gateway.Ports.Proxy)
938+
annotations[CoreComponentGatewayPortCloudEventsAnnotation] = fmt.Sprintf("%d", *c.Gateway.Ports.CloudEvents)
939+
annotations[CoreComponentGatewayNodePortProxyAnnotation] = fmt.Sprintf("%d", *c.Gateway.NodePorts.Proxy)
940+
annotations[CoreComponentGatewayNodePortCloudEventsAnnotation] = fmt.Sprintf("%d", *c.Gateway.NodePorts.CloudEvents)
941+
// Trigger
942+
annotations[CoreComponentTriggerReplicasAnnotation] = fmt.Sprintf("%d", *c.Trigger.Replicas)
943+
// Timer
944+
annotations[CoreComponentTimerTimingWheelTickAnnotation] = fmt.Sprintf("%d", *c.Timer.TimingWheel.Tick)
945+
annotations[CoreComponentTimerTimingWheelSizeAnnotation] = fmt.Sprintf("%d", *c.Timer.TimingWheel.Size)
946+
annotations[CoreComponentTimerTimingWheelLayersAnnotation] = fmt.Sprintf("%d", *c.Timer.TimingWheel.Layers)
947+
return annotations
948+
}

vsctl/command/global.go

Lines changed: 37 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -45,20 +45,44 @@ const (
4545
BaseUrl = "/api/v1"
4646
)
4747

48+
// Annotations supported by Core
4849
const (
49-
CoreComponentEtcdReplicasAnnotation = "core.vanus.ai/etcd-replicas"
50-
CoreComponentControllerReplicasAnnotation = "core.vanus.ai/controller-replicas"
51-
CoreComponentStoreReplicasAnnotation = "core.vanus.ai/store-replicas"
52-
CoreComponentGatewayReplicasAnnotation = "core.vanus.ai/gateway-replicas"
53-
CoreComponentTriggerReplicasAnnotation = "core.vanus.ai/trigger-replicas"
54-
CoreComponentTimerReplicasAnnotation = "core.vanus.ai/timer-replicas"
55-
CoreComponentEtcdStorageSizeAnnotation = "core.vanus.ai/etcd-storage-size"
56-
CoreComponentEtcdStorageClassAnnotation = "core.vanus.ai/etcd-storage-class"
57-
CoreComponentStoreStorageSizeAnnotation = "core.vanus.ai/store-storage-size"
58-
CoreComponentStoreStorageClassAnnotation = "core.vanus.ai/store-storage-class"
59-
ConnectorServiceTypeAnnotation = "connector.vanus.ai/service-type"
60-
ConnectorServicePortAnnotation = "connector.vanus.ai/service-port"
61-
ConnectorNetworkHostDomainAnnotation = "connector.vanus.ai/network-host-domain"
50+
// Etcd
51+
CoreComponentEtcdPortClientAnnotation = "core.vanus.ai/etcd-port-client"
52+
CoreComponentEtcdPortPeerAnnotation = "core.vanus.ai/etcd-port-peer"
53+
CoreComponentEtcdReplicasAnnotation = "core.vanus.ai/etcd-replicas"
54+
CoreComponentEtcdStorageSizeAnnotation = "core.vanus.ai/etcd-storage-size"
55+
CoreComponentEtcdStorageClassAnnotation = "core.vanus.ai/etcd-storage-class"
56+
// Controller
57+
CoreComponentControllerSvcPortAnnotation = "core.vanus.ai/controller-service-port"
58+
CoreComponentControllerReplicasAnnotation = "core.vanus.ai/controller-replicas"
59+
CoreComponentControllerSegmentCapacityAnnotation = "core.vanus.ai/controller-segment-capacity"
60+
// Root Controller
61+
CoreComponentRootControllerSvcPortAnnotation = "core.vanus.ai/root-controller-service-port"
62+
// Store
63+
CoreComponentStoreReplicasAnnotation = "core.vanus.ai/store-replicas"
64+
CoreComponentStoreStorageSizeAnnotation = "core.vanus.ai/store-storage-size"
65+
CoreComponentStoreStorageClassAnnotation = "core.vanus.ai/store-storage-class"
66+
// Gateway
67+
CoreComponentGatewayPortProxyAnnotation = "core.vanus.ai/gateway-port-proxy"
68+
CoreComponentGatewayPortCloudEventsAnnotation = "core.vanus.ai/gateway-port-cloudevents"
69+
CoreComponentGatewayNodePortProxyAnnotation = "core.vanus.ai/gateway-nodeport-proxy"
70+
CoreComponentGatewayNodePortCloudEventsAnnotation = "core.vanus.ai/gateway-nodeport-cloudevents"
71+
CoreComponentGatewayReplicasAnnotation = "core.vanus.ai/gateway-replicas"
72+
// Trigger
73+
CoreComponentTriggerReplicasAnnotation = "core.vanus.ai/trigger-replicas"
74+
// Timer
75+
CoreComponentTimerReplicasAnnotation = "core.vanus.ai/timer-replicas"
76+
CoreComponentTimerTimingWheelTickAnnotation = "core.vanus.ai/timer-timingwheel-tick"
77+
CoreComponentTimerTimingWheelSizeAnnotation = "core.vanus.ai/timer-timingwheel-size"
78+
CoreComponentTimerTimingWheelLayersAnnotation = "core.vanus.ai/timer-timingwheel-layers"
79+
)
80+
81+
// Annotations supported by Connector
82+
const (
83+
ConnectorServiceTypeAnnotation = "connector.vanus.ai/service-type"
84+
ConnectorServicePortAnnotation = "connector.vanus.ai/service-port"
85+
ConnectorNetworkHostDomainAnnotation = "connector.vanus.ai/network-host-domain"
6286
)
6387

6488
var retryTime = 30

0 commit comments

Comments
 (0)