Skip to content

Commit

Permalink
helm mode: use certgen for clustermesh connect
Browse files Browse the repository at this point in the history
Signed-off-by: Andrew Sauber <[email protected]>
  • Loading branch information
asauber committed May 15, 2023
1 parent 406d567 commit 09b4047
Showing 1 changed file with 35 additions and 25 deletions.
60 changes: 35 additions & 25 deletions clustermesh/clustermesh.go
Original file line number Diff line number Diff line change
Expand Up @@ -1854,45 +1854,30 @@ func (k *K8sClusterMesh) ConnectWithHelm(ctx context.Context) error {
return fmt.Errorf("remote and local cluster have the same, non-unique ID: %s", aiLocal.ClusterID)
}

// TODO (ajs): Support more than two clusters (dynamically append to config)
helmValues := map[string]interface{}{
"clustermesh": map[string]interface{}{
"config": map[string]interface{}{
"enabled": true,
"clusters": []map[string]interface{}{
map[string]interface{}{
"name": aiLocal.ClusterName,
// TODO (ajs): Support hostname-based endpoints
// include logic from patchConfig
"ips": []string{aiLocal.ServiceIPs[0]},
"port": aiLocal.ServicePort,
},
map[string]interface{}{
"name": aiRemote.ClusterName,
"ips": []string{aiRemote.ServiceIPs[0]},
"port": aiRemote.ServicePort,
},
},
},
},
}
helmValuesLocal := genClusterMeshConfig(aiLocal, aiRemote)
// We need a deep copy of these Helm values because `helm.Upgrade` mutates them!
helmValuesRemote := genClusterMeshConfig(aiRemote, aiLocal)

// TODO (ajs): Support hostname-based endpoints via --helm-values override
// Using the Helm value `extraDnsNames` should work as-is.
// This can be useful for LoadBalancer reachability.

// Enable clustermesh using a Helm Upgrade command
upgradeParams := helm.UpgradeParameters{
Namespace: k.params.Namespace,
Name: defaults.HelmReleaseName,
Values: helmValues,
Values: helmValuesLocal,
ResetValues: false,
ReuseValues: true,
}

// TODO (ajs): After classic mode removal, use a k8s.Client for k.client
// TODO (ajs): After classic mode removal, use a k8s.Client for this k.client
_, err = helm.Upgrade(ctx, k.client.(*k8s.Client).RESTClientGetter, upgradeParams)
if err != nil {
return err
}

// TODO (ajs): After classic mode removal, use a k8s.Client for k.client
upgradeParams.Values = helmValuesRemote
_, err = helm.Upgrade(ctx, remoteCluster.RESTClientGetter, upgradeParams)
if err != nil {
return err
Expand All @@ -1901,3 +1886,28 @@ func (k *K8sClusterMesh) ConnectWithHelm(ctx context.Context) error {
k.Log("✅ Connected cluster %s and %s!", k.client.ClusterName(), remoteCluster.ClusterName())
return nil
}

func genClusterMeshConfig(aiLocal, aiRemote *accessInformation) map[string]interface{} {
// TODO (ajs): Support more than two clusters
return map[string]interface{}{
"clustermesh": map[string]interface{}{
"config": map[string]interface{}{
"enabled": true,
// Use certgen to support Cilium versions less than v0.14
"method": "cronJob",
"clusters": []map[string]interface{}{
{
"name": aiLocal.ClusterName,
"ips": []string{aiLocal.ServiceIPs[0]},
"port": aiLocal.ServicePort,
},
{
"name": aiRemote.ClusterName,
"ips": []string{aiRemote.ServiceIPs[0]},
"port": aiRemote.ServicePort,
},
},
},
},
}
}

0 comments on commit 09b4047

Please sign in to comment.