Skip to content

Commit

Permalink
fix(cluster): allocate galaxy ipam service ip
Browse files Browse the repository at this point in the history
Signed-off-by: Tengfei Wang <[email protected]>
  • Loading branch information
davidwtf authored and tke-robot committed Jun 30, 2020
1 parent c3012eb commit a5bdb73
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 11 deletions.
12 changes: 9 additions & 3 deletions pkg/platform/controller/addon/ipam/ipam_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import (
v1 "tkestack.io/tke/api/platform/v1"
controllerutil "tkestack.io/tke/pkg/controller"
"tkestack.io/tke/pkg/platform/controller/addon/ipam/images"
"tkestack.io/tke/pkg/platform/provider/baremetal/constants"
"tkestack.io/tke/pkg/platform/util"
"tkestack.io/tke/pkg/util/log"
"tkestack.io/tke/pkg/util/metrics"
Expand Down Expand Up @@ -398,7 +399,11 @@ func (c *Controller) installIPAM(ctx context.Context, ipam *v1.IPAM) error {
return err
}
// Service IPAM
if _, err := kubeClient.CoreV1().Services(metav1.NamespaceSystem).Create(ctx, serviceIPAM(), metav1.CreateOptions{}); err != nil {
clusterIP := ""
if cluster.Annotations != nil {
clusterIP = cluster.Annotations[constants.GalaxyIPAMIPIndexAnnotaion]
}
if _, err := kubeClient.CoreV1().Services(metav1.NamespaceSystem).Create(ctx, serviceIPAM(clusterIP), metav1.CreateOptions{}); err != nil {
return err
}
log.Info("ipam installed")
Expand Down Expand Up @@ -640,7 +645,7 @@ func cmFloatingIP() *corev1.ConfigMap {
}
}

func serviceIPAM() *corev1.Service {
func serviceIPAM(clusterIP string) *corev1.Service {
return &corev1.Service{
TypeMeta: metav1.TypeMeta{
Kind: "Service",
Expand All @@ -652,7 +657,8 @@ func serviceIPAM() *corev1.Service {
Labels: map[string]string{"app": "galaxy-ipam"},
},
Spec: corev1.ServiceSpec{
Selector: map[string]string{"app": "galaxy-ipam"},
ClusterIP: clusterIP,
Selector: map[string]string{"app": "galaxy-ipam"},
Ports: []corev1.ServicePort{
{Name: "scheduler-port", Port: 9040, TargetPort: intstr.FromInt(9040)},
{Name: "api-port", Port: 9041, TargetPort: intstr.FromInt(9041)},
Expand Down
24 changes: 17 additions & 7 deletions pkg/platform/provider/baremetal/cluster/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ func (p *Provider) EnsureClusterComplete(ctx context.Context, cluster *v1.Cluste
funcs := []func(cluster *v1.Cluster) error{
completeNetworking,
completeDNS,
completeGPU,
completeServiceIP,
completeAddresses,
completeCredential,
}
Expand Down Expand Up @@ -315,15 +315,20 @@ func completeDNS(cluster *v1.Cluster) error {
return nil
}

func completeGPU(cluster *v1.Cluster) error {
ip, err := GetIndexedIP(cluster.Status.ServiceCIDR, constants.GPUQuotaAdmissionIPIndex)
if err != nil {
return errors.Wrap(err, "get gpu quota admission IP error")
}
func completeServiceIP(cluster *v1.Cluster) error {
if cluster.Annotations == nil {
cluster.Annotations = make(map[string]string)
}
cluster.Annotations[constants.GPUQuotaAdmissionIPAnnotaion] = ip.String()
for index, name := range map[int]string{
constants.GPUQuotaAdmissionIPIndex: constants.GPUQuotaAdmissionIPAnnotaion,
constants.GalaxyIPAMIPIndex: constants.GalaxyIPAMIPIndexAnnotaion,
} {
ip, err := GetIndexedIP(cluster.Status.ServiceCIDR, index)
if err != nil {
return errors.Wrap(err, "get service IP error")
}
cluster.Annotations[name] = ip.String()
}

return nil
}
Expand Down Expand Up @@ -572,8 +577,13 @@ func (p *Provider) EnsurePrepareForControlplane(ctx context.Context, c *v1.Clust
if GPUQuotaAdmissionHost == "" {
GPUQuotaAdmissionHost = "gpu-quota-admission"
}
GalaxyIPAMHost := c.Annotations[constants.GalaxyIPAMIPIndexAnnotaion]
if GalaxyIPAMHost == "" {
GalaxyIPAMHost = "galaxy-ipam"
}
schedulerPolicyConfig, err := template.ParseString(schedulerPolicyConfig, map[string]interface{}{
"GPUQuotaAdmissionHost": GPUQuotaAdmissionHost,
"GalaxyIPAMHost": GalaxyIPAMHost,
})
if err != nil {
return errors.Wrap(err, "parse schedulerPolicyConfig error")
Expand Down
2 changes: 1 addition & 1 deletion pkg/platform/provider/baremetal/cluster/manifests.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const (
}
],
"nodeCacheCapable" : false,
"urlPrefix" : "https://galaxy-ipam:9040/v1"
"urlPrefix" : "https://{{.GalaxyIPAMHost}}:9040/v1"
}
],
"kind" : "Policy"
Expand Down
2 changes: 2 additions & 0 deletions pkg/platform/provider/baremetal/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,9 @@ const (
KUBERNETES = 1
DNSIPIndex = 10
GPUQuotaAdmissionIPIndex = 9
GalaxyIPAMIPIndex = 8
GPUQuotaAdmissionIPAnnotaion = platformv1.GroupName + "/gpu-quota-admission-ip"
GalaxyIPAMIPIndexAnnotaion = platformv1.GroupName + "/galaxy-ipam-ip"

// RenewCertsTimeThreshold control how long time left to renew certs
RenewCertsTimeThreshold = 30 * 24 * time.Hour
Expand Down

0 comments on commit a5bdb73

Please sign in to comment.