diff --git a/apis/milvus.io/v1alpha1/milvus_webhook.go b/apis/milvus.io/v1alpha1/milvus_webhook.go index a8ab2f5..7c136e6 100644 --- a/apis/milvus.io/v1alpha1/milvus_webhook.go +++ b/apis/milvus.io/v1alpha1/milvus_webhook.go @@ -52,7 +52,6 @@ func (r *MilvusSpec) ConvertSpecTo(dst *v1beta1.MilvusSpec) { Component: v1beta1.Component{ ComponentSpec: r.ComponentSpec, Replicas: r.Replicas, - Port: 19530, }, ServiceType: r.ServiceType, ServiceLabels: r.ServiceLabels, diff --git a/apis/milvus.io/v1beta1/components_types.go b/apis/milvus.io/v1beta1/components_types.go index c908ca0..e44fd29 100644 --- a/apis/milvus.io/v1beta1/components_types.go +++ b/apis/milvus.io/v1beta1/components_types.go @@ -227,12 +227,6 @@ type Component struct { // when replicas is -1, it means the replicas should be managed by HPA Replicas *int32 `json:"replicas,omitempty"` - // +kubebuilder:validation:Optional - // +kubebuilder:validation:Minimum=0 - // +kubebuilder:validation:Maximum=65535 - // not used for now - Port int32 `json:"port,omitempty"` - // SideCars is same as []corev1.Container, we use a Values here to avoid the CRD become too large // +kubebuilder:validation:Optional // +kubebuilder:pruning:PreserveUnknownFields @@ -294,6 +288,12 @@ type ServiceComponent struct { // +kubebuilder:default="ClusterIP" ServiceType corev1.ServiceType `json:"serviceType,omitempty"` + // Port of grpc service, if not set or <=0, default to 19530 + // +kubebuilder:validation:Optional + // +kubebuilder:validation:Minimum=0 + // +kubebuilder:validation:Maximum=65535 + Port int32 `json:"port,omitempty"` + // +kubebuilder:validation:Optional ServiceRestfulPort int32 `json:"serviceRestfulPort,omitempty"` diff --git a/apis/milvus.io/v1beta1/milvus_webhook.go b/apis/milvus.io/v1beta1/milvus_webhook.go index a6c83b9..361fdab 100644 --- a/apis/milvus.io/v1beta1/milvus_webhook.go +++ b/apis/milvus.io/v1beta1/milvus_webhook.go @@ -193,13 +193,6 @@ func deleteUnsettableConf(conf map[string]interface{}) { util.DeleteValue(conf, "pulsar", "address") util.DeleteValue(conf, "pulsar", "port") util.DeleteValue(conf, "etcd", "endpoints") - - for _, t := range MilvusComponentTypes { - util.DeleteValue(conf, t.String(), "port") - } - for _, t := range MilvusCoordTypes { - util.DeleteValue(conf, t.String(), "address") - } } var ( diff --git a/charts/milvus-operator/templates/crds.yaml b/charts/milvus-operator/templates/crds.yaml index 5f48631..d28328b 100644 --- a/charts/milvus-operator/templates/crds.yaml +++ b/charts/milvus-operator/templates/crds.yaml @@ -875,11 +875,6 @@ spec: additionalProperties: type: string type: object - port: - format: int32 - maximum: 65535 - minimum: 0 - type: integer priorityClassName: type: string replicas: @@ -1440,11 +1435,6 @@ spec: additionalProperties: type: string type: object - port: - format: int32 - maximum: 65535 - minimum: 0 - type: integer priorityClassName: type: string replicas: @@ -2099,11 +2089,6 @@ spec: additionalProperties: type: string type: object - port: - format: int32 - maximum: 65535 - minimum: 0 - type: integer priorityClassName: type: string replicas: @@ -2664,11 +2649,6 @@ spec: additionalProperties: type: string type: object - port: - format: int32 - maximum: 65535 - minimum: 0 - type: integer priorityClassName: type: string replicas: @@ -3231,11 +3211,6 @@ spec: additionalProperties: type: string type: object - port: - format: int32 - maximum: 65535 - minimum: 0 - type: integer priorityClassName: type: string replicas: @@ -4418,11 +4393,6 @@ spec: additionalProperties: type: string type: object - port: - format: int32 - maximum: 65535 - minimum: 0 - type: integer priorityClassName: type: string replicas: @@ -4983,11 +4953,6 @@ spec: additionalProperties: type: string type: object - port: - format: int32 - maximum: 65535 - minimum: 0 - type: integer priorityClassName: type: string replicas: @@ -5581,11 +5546,6 @@ spec: additionalProperties: type: string type: object - port: - format: int32 - maximum: 65535 - minimum: 0 - type: integer priorityClassName: type: string replicas: @@ -8542,11 +8502,6 @@ spec: additionalProperties: type: string type: object - port: - format: int32 - maximum: 65535 - minimum: 0 - type: integer priorityClassName: type: string replicas: @@ -9107,11 +9062,6 @@ spec: additionalProperties: type: string type: object - port: - format: int32 - maximum: 65535 - minimum: 0 - type: integer priorityClassName: type: string replicas: @@ -9766,11 +9716,6 @@ spec: additionalProperties: type: string type: object - port: - format: int32 - maximum: 65535 - minimum: 0 - type: integer priorityClassName: type: string replicas: @@ -10331,11 +10276,6 @@ spec: additionalProperties: type: string type: object - port: - format: int32 - maximum: 65535 - minimum: 0 - type: integer priorityClassName: type: string replicas: @@ -10898,11 +10838,6 @@ spec: additionalProperties: type: string type: object - port: - format: int32 - maximum: 65535 - minimum: 0 - type: integer priorityClassName: type: string replicas: @@ -12085,11 +12020,6 @@ spec: additionalProperties: type: string type: object - port: - format: int32 - maximum: 65535 - minimum: 0 - type: integer priorityClassName: type: string replicas: @@ -12650,11 +12580,6 @@ spec: additionalProperties: type: string type: object - port: - format: int32 - maximum: 65535 - minimum: 0 - type: integer priorityClassName: type: string replicas: @@ -13248,11 +13173,6 @@ spec: additionalProperties: type: string type: object - port: - format: int32 - maximum: 65535 - minimum: 0 - type: integer priorityClassName: type: string replicas: diff --git a/config/crd/bases/milvus.io_milvusclusters.yaml b/config/crd/bases/milvus.io_milvusclusters.yaml index 1db0a25..bfdb631 100644 --- a/config/crd/bases/milvus.io_milvusclusters.yaml +++ b/config/crd/bases/milvus.io_milvusclusters.yaml @@ -873,11 +873,6 @@ spec: additionalProperties: type: string type: object - port: - format: int32 - maximum: 65535 - minimum: 0 - type: integer priorityClassName: type: string replicas: @@ -1438,11 +1433,6 @@ spec: additionalProperties: type: string type: object - port: - format: int32 - maximum: 65535 - minimum: 0 - type: integer priorityClassName: type: string replicas: @@ -2097,11 +2087,6 @@ spec: additionalProperties: type: string type: object - port: - format: int32 - maximum: 65535 - minimum: 0 - type: integer priorityClassName: type: string replicas: @@ -2662,11 +2647,6 @@ spec: additionalProperties: type: string type: object - port: - format: int32 - maximum: 65535 - minimum: 0 - type: integer priorityClassName: type: string replicas: @@ -3229,11 +3209,6 @@ spec: additionalProperties: type: string type: object - port: - format: int32 - maximum: 65535 - minimum: 0 - type: integer priorityClassName: type: string replicas: @@ -4416,11 +4391,6 @@ spec: additionalProperties: type: string type: object - port: - format: int32 - maximum: 65535 - minimum: 0 - type: integer priorityClassName: type: string replicas: @@ -4981,11 +4951,6 @@ spec: additionalProperties: type: string type: object - port: - format: int32 - maximum: 65535 - minimum: 0 - type: integer priorityClassName: type: string replicas: @@ -5579,11 +5544,6 @@ spec: additionalProperties: type: string type: object - port: - format: int32 - maximum: 65535 - minimum: 0 - type: integer priorityClassName: type: string replicas: diff --git a/config/crd/bases/milvus.io_milvuses.yaml b/config/crd/bases/milvus.io_milvuses.yaml index 29b90d5..d402a93 100644 --- a/config/crd/bases/milvus.io_milvuses.yaml +++ b/config/crd/bases/milvus.io_milvuses.yaml @@ -1851,11 +1851,6 @@ spec: additionalProperties: type: string type: object - port: - format: int32 - maximum: 65535 - minimum: 0 - type: integer priorityClassName: type: string replicas: @@ -2416,11 +2411,6 @@ spec: additionalProperties: type: string type: object - port: - format: int32 - maximum: 65535 - minimum: 0 - type: integer priorityClassName: type: string replicas: @@ -3075,11 +3065,6 @@ spec: additionalProperties: type: string type: object - port: - format: int32 - maximum: 65535 - minimum: 0 - type: integer priorityClassName: type: string replicas: @@ -3640,11 +3625,6 @@ spec: additionalProperties: type: string type: object - port: - format: int32 - maximum: 65535 - minimum: 0 - type: integer priorityClassName: type: string replicas: @@ -4207,11 +4187,6 @@ spec: additionalProperties: type: string type: object - port: - format: int32 - maximum: 65535 - minimum: 0 - type: integer priorityClassName: type: string replicas: @@ -5394,11 +5369,6 @@ spec: additionalProperties: type: string type: object - port: - format: int32 - maximum: 65535 - minimum: 0 - type: integer priorityClassName: type: string replicas: @@ -5959,11 +5929,6 @@ spec: additionalProperties: type: string type: object - port: - format: int32 - maximum: 65535 - minimum: 0 - type: integer priorityClassName: type: string replicas: @@ -6557,11 +6522,6 @@ spec: additionalProperties: type: string type: object - port: - format: int32 - maximum: 65535 - minimum: 0 - type: integer priorityClassName: type: string replicas: diff --git a/config/samples/cluster_demo.yaml b/config/samples/cluster_demo.yaml index e1a0817..991bd27 100644 --- a/config/samples/cluster_demo.yaml +++ b/config/samples/cluster_demo.yaml @@ -12,7 +12,7 @@ metadata: spec: mode: cluster config: {} - components: + components: enableRollingUpdate: true imageUpdateMode: rollingUpgrade proxy: @@ -41,7 +41,7 @@ spec: requests: memory: 100Mi persistence: - size: 20Gi + size: 20Gi deletionPolicy: Delete pvcDeletion: true msgStreamType: kafka diff --git a/deploy/manifests/deployment.yaml b/deploy/manifests/deployment.yaml index fd75ce1..4ab1346 100644 --- a/deploy/manifests/deployment.yaml +++ b/deploy/manifests/deployment.yaml @@ -906,11 +906,6 @@ spec: additionalProperties: type: string type: object - port: - format: int32 - maximum: 65535 - minimum: 0 - type: integer priorityClassName: type: string replicas: @@ -1471,11 +1466,6 @@ spec: additionalProperties: type: string type: object - port: - format: int32 - maximum: 65535 - minimum: 0 - type: integer priorityClassName: type: string replicas: @@ -2130,11 +2120,6 @@ spec: additionalProperties: type: string type: object - port: - format: int32 - maximum: 65535 - minimum: 0 - type: integer priorityClassName: type: string replicas: @@ -2695,11 +2680,6 @@ spec: additionalProperties: type: string type: object - port: - format: int32 - maximum: 65535 - minimum: 0 - type: integer priorityClassName: type: string replicas: @@ -3262,11 +3242,6 @@ spec: additionalProperties: type: string type: object - port: - format: int32 - maximum: 65535 - minimum: 0 - type: integer priorityClassName: type: string replicas: @@ -4449,11 +4424,6 @@ spec: additionalProperties: type: string type: object - port: - format: int32 - maximum: 65535 - minimum: 0 - type: integer priorityClassName: type: string replicas: @@ -5014,11 +4984,6 @@ spec: additionalProperties: type: string type: object - port: - format: int32 - maximum: 65535 - minimum: 0 - type: integer priorityClassName: type: string replicas: @@ -5612,11 +5577,6 @@ spec: additionalProperties: type: string type: object - port: - format: int32 - maximum: 65535 - minimum: 0 - type: integer priorityClassName: type: string replicas: @@ -8574,11 +8534,6 @@ spec: additionalProperties: type: string type: object - port: - format: int32 - maximum: 65535 - minimum: 0 - type: integer priorityClassName: type: string replicas: @@ -9139,11 +9094,6 @@ spec: additionalProperties: type: string type: object - port: - format: int32 - maximum: 65535 - minimum: 0 - type: integer priorityClassName: type: string replicas: @@ -9798,11 +9748,6 @@ spec: additionalProperties: type: string type: object - port: - format: int32 - maximum: 65535 - minimum: 0 - type: integer priorityClassName: type: string replicas: @@ -10363,11 +10308,6 @@ spec: additionalProperties: type: string type: object - port: - format: int32 - maximum: 65535 - minimum: 0 - type: integer priorityClassName: type: string replicas: @@ -10930,11 +10870,6 @@ spec: additionalProperties: type: string type: object - port: - format: int32 - maximum: 65535 - minimum: 0 - type: integer priorityClassName: type: string replicas: @@ -12117,11 +12052,6 @@ spec: additionalProperties: type: string type: object - port: - format: int32 - maximum: 65535 - minimum: 0 - type: integer priorityClassName: type: string replicas: @@ -12682,11 +12612,6 @@ spec: additionalProperties: type: string type: object - port: - format: int32 - maximum: 65535 - minimum: 0 - type: integer priorityClassName: type: string replicas: @@ -13280,11 +13205,6 @@ spec: additionalProperties: type: string type: object - port: - format: int32 - maximum: 65535 - minimum: 0 - type: integer priorityClassName: type: string replicas: diff --git a/pkg/controllers/components.go b/pkg/controllers/components.go index d402add..9fe2c2c 100644 --- a/pkg/controllers/components.go +++ b/pkg/controllers/components.go @@ -233,22 +233,6 @@ func (c MilvusComponent) GetPortName() string { return c.Name } -// GetContainerPorts returns the ports of the component container -func (c MilvusComponent) GetContainerPorts(spec v1beta1.MilvusSpec) []corev1.ContainerPort { - return []corev1.ContainerPort{ - { - Name: c.GetPortName(), - ContainerPort: c.GetComponentPort(spec), - Protocol: corev1.ProtocolTCP, - }, - { - Name: MetricPortName, - ContainerPort: MetricPort, - Protocol: corev1.ProtocolTCP, - }, - } -} - func (c MilvusComponent) IsService() bool { return c == Proxy || c == MilvusStandalone } @@ -308,6 +292,12 @@ func (c MilvusComponent) GetServicePorts(spec v1beta1.MilvusSpec) []corev1.Servi // GetComponentPort returns the port of the component func (c MilvusComponent) GetComponentPort(spec v1beta1.MilvusSpec) int32 { + if c == Proxy || c == MilvusStandalone { + svcPort := spec.GetServiceComponent().Port + if svcPort > 0 { + return svcPort + } + } return c.DefaultPort } diff --git a/pkg/controllers/components_test.go b/pkg/controllers/components_test.go index 6c297f6..8759744 100644 --- a/pkg/controllers/components_test.go +++ b/pkg/controllers/components_test.go @@ -322,15 +322,6 @@ func TestMilvusComponent_GetContainerName(t *testing.T) { assert.Equal(t, com.Name, com.GetContainerName()) } -func TestMilvusComponent_GetContainerPorts(t *testing.T) { - com := QueryNode - spec := newSpecCluster() - ports := com.GetContainerPorts(spec) - assert.Equal(t, 2, len(ports)) - assert.Equal(t, com.DefaultPort, ports[0].ContainerPort) - assert.Equal(t, int32(MetricPort), ports[1].ContainerPort) -} - func TestMilvusComponent_GetServiceType(t *testing.T) { com := QueryNode spec := newSpecCluster() @@ -424,8 +415,14 @@ func TestMilvusComponent_GetComponentPort(t *testing.T) { spec := newSpecCluster() assert.Equal(t, com.DefaultPort, com.GetComponentPort(spec)) - spec.Com.QueryNode.Component.Port = 8080 - assert.Equal(t, QueryNode.DefaultPort, com.GetComponentPort(spec)) + com = Proxy + spec.Com.Proxy.Port = 19532 + assert.Equal(t, spec.Com.Proxy.Port, com.GetComponentPort(spec)) + + com = MilvusStandalone + spec = newSpec() + spec.Com.Standalone.Port = 19533 + assert.Equal(t, spec.Com.Standalone.Port, com.GetComponentPort(spec)) } func TestMilvusComponent_GetComponentSpec(t *testing.T) { diff --git a/pkg/controllers/deploy_ctrl_util.go b/pkg/controllers/deploy_ctrl_util.go index b3b0acc..da45fca 100644 --- a/pkg/controllers/deploy_ctrl_util.go +++ b/pkg/controllers/deploy_ctrl_util.go @@ -94,7 +94,7 @@ func (c *DeployControllerBizUtilImpl) RenderPodTemplateWithoutGroupID(mc v1beta1 ret = currentTemplate.DeepCopy() } updater := newMilvusDeploymentUpdater(mc, c.cli.Scheme(), component) - appLabels := NewComponentAppLabels(updater.GetIntanceName(), updater.GetComponentName()) + appLabels := NewComponentAppLabels(updater.GetIntanceName(), updater.GetComponent().Name) isCreating := currentTemplate == nil isStopped := ReplicasValue(component.GetReplicas(mc.Spec)) == 0 updateDefaults := isCreating || isStopped diff --git a/pkg/controllers/deployment_updater.go b/pkg/controllers/deployment_updater.go index 9022e75..898dbbc 100644 --- a/pkg/controllers/deployment_updater.go +++ b/pkg/controllers/deployment_updater.go @@ -16,8 +16,7 @@ import ( type deploymentUpdater interface { GetIntanceName() string - GetComponentName() string - GetPortName() string + GetComponent() MilvusComponent GetRestfulPort() int32 GetControllerRef() metav1.Object GetScheme() *runtime.Scheme @@ -63,7 +62,7 @@ func updateDeploymentReplicas(deployment *appsv1.Deployment, updater deploymentU } func updateDeployment(deployment *appsv1.Deployment, updater deploymentUpdater) error { - appLabels := NewComponentAppLabels(updater.GetIntanceName(), updater.GetComponentName()) + appLabels := NewComponentAppLabels(updater.GetIntanceName(), updater.GetComponent().Name) deployment.Labels = MergeLabels(deployment.Labels, appLabels) if err := SetControllerReference(updater.GetControllerRef(), deployment, updater.GetScheme()); err != nil { return pkgErrs.Wrap(err, "set controller reference") @@ -234,11 +233,11 @@ func updateBuiltInVolumes(template *corev1.PodTemplateSpec, updater deploymentUp func updateMilvusContainer(template *corev1.PodTemplateSpec, updater deploymentUpdater, isCreating bool) { mergedComSpec := updater.GetMergedComponentSpec() - containerIdx := GetContainerIndex(template.Spec.Containers, updater.GetComponentName()) + containerIdx := GetContainerIndex(template.Spec.Containers, updater.GetComponent().Name) if containerIdx < 0 { template.Spec.Containers = append( template.Spec.Containers, - corev1.Container{Name: updater.GetComponentName()}, + corev1.Container{Name: updater.GetComponent().Name}, ) containerIdx = len(template.Spec.Containers) - 1 } @@ -252,12 +251,12 @@ func updateMilvusContainer(template *corev1.PodTemplateSpec, updater deploymentU ContainerPort: MetricPort, Protocol: corev1.ProtocolTCP, } - componentName := updater.GetComponentName() + componentName := updater.GetComponent().Name if componentName == ProxyName || componentName == StandaloneName { container.Ports = []corev1.ContainerPort{ { - Name: updater.GetPortName(), - ContainerPort: MilvusPort, + Name: updater.GetComponent().GetPortName(), + ContainerPort: updater.GetComponent().GetComponentPort(updater.GetMilvus().Spec), Protocol: corev1.ProtocolTCP, }, metricPort, @@ -291,7 +290,7 @@ func updateMilvusContainer(template *corev1.PodTemplateSpec, updater deploymentU } func updateBuiltInVolumeMounts(template *corev1.PodTemplateSpec, updater deploymentUpdater) { - containerIdx := GetContainerIndex(template.Spec.Containers, updater.GetComponentName()) + containerIdx := GetContainerIndex(template.Spec.Containers, updater.GetComponent().Name) if containerIdx < 0 { return } @@ -320,8 +319,8 @@ func updateSomeFieldsOnlyWhenRolling(template *corev1.PodTemplateSpec, updater d updateBuiltInVolumes(template, updater) updateBuiltInVolumeMounts(template, updater) updateConfigContainer(template, updater) - componentName := updater.GetComponentName() - containerIdx := GetContainerIndex(template.Spec.Containers, updater.GetComponentName()) + componentName := updater.GetComponent().Name + containerIdx := GetContainerIndex(template.Spec.Containers, updater.GetComponent().Name) container := &template.Spec.Containers[containerIdx] if componentName == ProxyName || componentName == StandaloneName { template.Labels[v1beta1.ServiceLabel] = v1beta1.TrueStr @@ -390,14 +389,15 @@ func (m milvusDeploymentUpdater) GetPersistenceConfig() *v1beta1.Persistence { func (m milvusDeploymentUpdater) GetIntanceName() string { return m.Name } -func (m milvusDeploymentUpdater) GetComponentName() string { - return m.component.GetName() -} func (m milvusDeploymentUpdater) GetPortName() string { return m.component.GetPortName() } +func (m milvusDeploymentUpdater) GetComponent() MilvusComponent { + return m.component +} + func (m milvusDeploymentUpdater) GetRestfulPort() int32 { return m.component.GetRestfulPort(m.Spec) } diff --git a/test/min-mc-feature.yaml b/test/min-mc-feature.yaml index d472013..2253c4f 100644 --- a/test/min-mc-feature.yaml +++ b/test/min-mc-feature.yaml @@ -12,23 +12,23 @@ metadata: labels: app: milvus spec: - mode: "cluster" + mode: 'cluster' components: rollingMode: 3 runWithSubProcess: true runAsNonRoot: true proxy: ingress: - hosts: ["mc-sit.milvus.io"] + hosts: ['mc-sit.milvus.io'] replicas: 1 mixCoord: replicas: 1 volumes: - - emptyDir: {} - name: data + - emptyDir: {} + name: data volumeMounts: - - mountPath: /milvus/data - name: data + - mountPath: /milvus/data + name: data dependencies: etcd: inCluster: @@ -67,3 +67,5 @@ spec: milvus: log: level: info + rootCoord: + port: 13000