-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #58 from pdettori/vcluster
✨ add support for vcluster control planes
- Loading branch information
Showing
11 changed files
with
212 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/* | ||
Copyright 2023 The KubeStellar Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package vcluster | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"strings" | ||
|
||
tenancyv1alpha1 "github.com/kubestellar/kubeflex/api/v1alpha1" | ||
"github.com/kubestellar/kubeflex/pkg/helm" | ||
"github.com/kubestellar/kubeflex/pkg/util" | ||
) | ||
|
||
// helm upgrade --install <controlplane-name> vcluster \ | ||
// --set vcluster.image=rancher/k3s:v1.27.2-k3s1 \ | ||
// --repo https://charts.loft.sh \ | ||
// --namespace <controlplane-name>-system \ | ||
// --repository-config='' \ | ||
// --create-namespace | ||
|
||
// Need also | ||
// syncer: | ||
// extraArgs: | ||
// - --tls-san=<controlplane-name>.localtest.me | ||
// - --out-kube-config-server=https://<controlplane-name>.localtest.me:9443 | ||
|
||
const ( | ||
URL = "https://charts.loft.sh" | ||
RepoName = "loft" | ||
ChartName = "vcluster" | ||
ReleaseName = "vcluster" | ||
) | ||
|
||
var ( | ||
configs = []string{ | ||
"vcluster.image=rancher/k3s:v1.27.2-k3s1", | ||
} | ||
) | ||
|
||
func (r *VClusterReconciler) ReconcileChart(ctx context.Context, hcp *tenancyv1alpha1.ControlPlane) error { | ||
localDNSName := util.GenerateDevLocalDNSName(hcp.Name) | ||
configs = append(configs, fmt.Sprintf("syncer.extraArgs[0]=--tls-san=%s", localDNSName)) | ||
configs = append(configs, fmt.Sprintf("syncer.extraArgs[1]=--out-kube-config-server=https://%s:9443", localDNSName)) | ||
h := &helm.HelmHandler{ | ||
URL: URL, | ||
RepoName: RepoName, | ||
ChartName: ChartName, | ||
Namespace: util.GenerateNamespaceFromControlPlaneName(hcp.Name), | ||
ReleaseName: ReleaseName, | ||
Args: map[string]string{"set": strings.Join(configs, ",")}, | ||
} | ||
err := helm.Init(ctx, h) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if !h.IsDeployed() { | ||
err := h.Install() | ||
if err != nil { | ||
return err | ||
} | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* | ||
Copyright 2023 The KubeStellar Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package vcluster | ||
|
||
import ( | ||
"context" | ||
|
||
"k8s.io/apimachinery/pkg/runtime" | ||
ctrl "sigs.k8s.io/controller-runtime" | ||
"sigs.k8s.io/controller-runtime/pkg/client" | ||
clog "sigs.k8s.io/controller-runtime/pkg/log" | ||
|
||
tenancyv1alpha1 "github.com/kubestellar/kubeflex/api/v1alpha1" | ||
"github.com/kubestellar/kubeflex/pkg/reconcilers/shared" | ||
) | ||
|
||
const ( | ||
ServiceName = "vcluster" | ||
ServicePort = 443 | ||
) | ||
|
||
// VClusterReconciler reconciles a OCM ControlPlane | ||
type VClusterReconciler struct { | ||
*shared.BaseReconciler | ||
} | ||
|
||
func New(cl client.Client, scheme *runtime.Scheme) *VClusterReconciler { | ||
return &VClusterReconciler{ | ||
BaseReconciler: &shared.BaseReconciler{ | ||
Client: cl, | ||
Scheme: scheme, | ||
}, | ||
} | ||
} | ||
|
||
func (r *VClusterReconciler) Reconcile(ctx context.Context, hcp *tenancyv1alpha1.ControlPlane) (ctrl.Result, error) { | ||
_ = clog.FromContext(ctx) | ||
|
||
if err := r.BaseReconciler.ReconcileNamespace(ctx, hcp); err != nil { | ||
return r.UpdateStatusForSyncingError(hcp, err) | ||
} | ||
|
||
if err := r.ReconcileChart(ctx, hcp); err != nil { | ||
return r.UpdateStatusForSyncingError(hcp, err) | ||
} | ||
|
||
if err := r.ReconcileAPIServerIngress(ctx, hcp, ServiceName, ServicePort); err != nil { | ||
return r.UpdateStatusForSyncingError(hcp, err) | ||
} | ||
|
||
return r.UpdateStatusForSyncingSuccess(ctx, hcp) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters