Skip to content

Commit

Permalink
feat(platform): support customize flannel backend type
Browse files Browse the repository at this point in the history
  • Loading branch information
gmemcc authored and tke-robot committed Sep 29, 2020
1 parent 00bd983 commit fb9dec1
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 10 deletions.
2 changes: 2 additions & 0 deletions api/platform/v1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ type ClusterSpec struct {
// +optional
NetworkType NetworkType `json:"networkType,omitempty" protobuf:"bytes,6,opt,name=networkType,casttype=NetworkType"`
// +optional
NetworkArgs map[string]string `json:"networkArgs,omitempty" protobuf:"bytes,23,name=networkArgs"`
// +optional
NetworkDevice string `json:"networkDevice,omitempty" protobuf:"bytes,7,opt,name=networkDevice"`
// +optional
ClusterCIDR string `json:"clusterCIDR,omitempty" protobuf:"bytes,8,opt,name=clusterCIDR"`
Expand Down
15 changes: 12 additions & 3 deletions pkg/platform/provider/baremetal/cluster/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -773,10 +773,19 @@ func (p *Provider) EnsureGalaxy(ctx context.Context, c *v1.Cluster) error {
if err != nil {
return err
}
backendType := "vxlan"
clusterSpec := c.Cluster.Spec
if clusterSpec.NetworkArgs != nil {
backendTypeArg, ok := clusterSpec.NetworkArgs["backendType"]
if ok {
backendType = backendTypeArg
}
}
return galaxy.Install(ctx, clientset, &galaxy.Option{
Version: galaxyimages.LatestVersion,
NodeCIDR: c.Cluster.Spec.ClusterCIDR,
NetDevice: c.Cluster.Spec.NetworkDevice,
Version: galaxyimages.LatestVersion,
NodeCIDR: clusterSpec.ClusterCIDR,
NetDevice: clusterSpec.NetworkDevice,
BackendType: backendType,
})
}

Expand Down
15 changes: 9 additions & 6 deletions pkg/platform/provider/baremetal/phases/galaxy/galaxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,10 @@ const (

// Option for coredns
type Option struct {
Version string
NodeCIDR string
NetDevice string
Version string
NodeCIDR string
NetDevice string
BackendType string
}

// Install to install the galaxy workload
Expand All @@ -78,7 +79,7 @@ func Install(ctx context.Context, clientset kubernetes.Interface, option *Option
if !errors.IsNotFound(err) {
return err
}
cm, err := configMapFlannel(option.NodeCIDR)
cm, err := configMapFlannel(option.NodeCIDR, option.BackendType)
if err != nil {
return err
}
Expand Down Expand Up @@ -148,8 +149,10 @@ func cleanFlannelInterfaces() error {
return err
}

func configMapFlannel(clusterCIDR string) (*corev1.ConfigMap, error) {
reader := strings.NewReader(strings.Replace(FlannelCM, "{{ .Network }}", clusterCIDR, 1))
func configMapFlannel(clusterCIDR, backendType string) (*corev1.ConfigMap, error) {
flannelCM := strings.Replace(FlannelCM, "{{ .Network }}", clusterCIDR, 1)
flannelCM = strings.Replace(flannelCM, "{{ .Type }}", backendType, 1)
reader := strings.NewReader(flannelCM)
decoder := yaml.NewYAMLOrJSONDecoder(reader, 4096)
payload := &corev1.ConfigMap{}
err := decoder.Decode(payload)
Expand Down
2 changes: 1 addition & 1 deletion pkg/platform/provider/baremetal/phases/galaxy/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ data:
{
"Network": "{{ .Network }}",
"Backend": {
"Type": "vxlan"
"Type": "{{ .Type }}"
}
}
`
Expand Down

0 comments on commit fb9dec1

Please sign in to comment.