-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
390 additions
and
1 deletion.
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
Empty file.
12 changes: 12 additions & 0 deletions
12
...ntime-extensions-nutanix/templates/cosi/controller/manifests/helm-addon-installation.yaml
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,12 @@ | ||
# Copyright 2024 Nutanix. All rights reserved. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
{{- if (index .Values.hooks.cosi "controller").helmAddonStrategy.defaultValueTemplateConfigMap.create }} | ||
apiVersion: v1 | ||
kind: ConfigMap | ||
metadata: | ||
name: '{{ (index .Values.hooks.cosi "controller").helmAddonStrategy.defaultValueTemplateConfigMap.name }}' | ||
data: | ||
values.yaml: |- | ||
{{- .Files.Get "addons/cosi/controller/values-template.yaml" | nindent 4 }} | ||
{{- end -}} |
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,32 @@ | ||
+++ | ||
title = " Container Object Storage Interface (COSI)" | ||
icon = "fa-solid fa-eye" | ||
+++ | ||
|
||
By leveraging CAPI cluster lifecycle hooks, this handler deploys [Container Object Storage Interface] (COSI) | ||
on the new cluster at the `AfterControlPlaneInitialized` phase. | ||
|
||
Deployment of COSI is opt-in via the [provider-specific cluster configuration]({{< ref ".." >}}). | ||
|
||
The hook uses the [Cluster API Add-on Provider for Helm] to deploy the NFD resources. | ||
|
||
## Example | ||
|
||
To enable deployment of COSI on a cluster, specify the following values: | ||
|
||
```yaml | ||
apiVersion: cluster.x-k8s.io/v1beta1 | ||
kind: Cluster | ||
metadata: | ||
name: <NAME> | ||
spec: | ||
topology: | ||
variables: | ||
- name: clusterConfig | ||
value: | ||
addons: | ||
cosi: {} | ||
``` | ||
[Container Object Storage Interface]: https://kubernetes.io/blog/2022/09/02/cosi-kubernetes-object-storage-management/ | ||
[Cluster API Add-on Provider for Helm]: https://github.com/kubernetes-sigs/cluster-api-addon-provider-helm |
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
17 changes: 17 additions & 0 deletions
17
hack/addons/kustomize/cosi-controller/kustomization.yaml.tmpl
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,17 @@ | ||
# Copyright 2024 Nutanix. All rights reserved. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
apiVersion: kustomize.config.k8s.io/v1beta1 | ||
kind: Kustomization | ||
|
||
metadata: | ||
name: cosi-controller-kustomize | ||
|
||
helmCharts: | ||
- name: cosi | ||
namespace: container-object-storage-system | ||
repo: https://mesosphere.github.io/charts/stable/ | ||
releaseName: cosi-controller | ||
version: ${COSI_CONTROLLER_VERSION} | ||
includeCRDs: true | ||
skipTests: true |
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,8 @@ | ||
// Copyright 2023 Nutanix. All rights reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
// Package COSI provides a handler for managing NFD deployments on clusters | ||
// | ||
// +kubebuilder:rbac:groups=addons.cluster.x-k8s.io,resources=clusterresourcesets,verbs=watch;list;get;create;patch;update;delete | ||
// +kubebuilder:rbac:groups="",resources=configmaps,verbs=watch;list;get;create;patch;update;delete | ||
package cosi |
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,192 @@ | ||
// Copyright 2023 Nutanix. All rights reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package cosi | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/spf13/pflag" | ||
"k8s.io/utils/ptr" | ||
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" | ||
runtimehooksv1 "sigs.k8s.io/cluster-api/exp/runtime/hooks/api/v1alpha1" | ||
ctrl "sigs.k8s.io/controller-runtime" | ||
ctrlclient "sigs.k8s.io/controller-runtime/pkg/client" | ||
|
||
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/api/v1alpha1" | ||
apivariables "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/api/variables" | ||
commonhandlers "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/capi/clustertopology/handlers" | ||
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/capi/clustertopology/handlers/lifecycle" | ||
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/capi/clustertopology/variables" | ||
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/generic/lifecycle/addons" | ||
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/generic/lifecycle/config" | ||
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/options" | ||
) | ||
|
||
const ( | ||
defaultHelmReleaseName = "cosi-controller" | ||
defaultHelmReleaseNamespace = "container-object-storage-system" | ||
) | ||
|
||
type ControllerConfig struct { | ||
*options.GlobalOptions | ||
|
||
helmAddonConfig *addons.HelmAddonConfig | ||
} | ||
|
||
func NewControllerConfig(globalOptions *options.GlobalOptions) *ControllerConfig { | ||
return &ControllerConfig{ | ||
GlobalOptions: globalOptions, | ||
helmAddonConfig: addons.NewHelmAddonConfig( | ||
"default-cosi-controller-helm-values-template", | ||
defaultHelmReleaseNamespace, | ||
defaultHelmReleaseName, | ||
), | ||
} | ||
} | ||
|
||
func (c *ControllerConfig) AddFlags(prefix string, flags *pflag.FlagSet) { | ||
c.helmAddonConfig.AddFlags(prefix+".helm-addon", flags) | ||
} | ||
|
||
type DefaultCOSIController struct { | ||
client ctrlclient.Client | ||
config *ControllerConfig | ||
helmChartInfoGetter *config.HelmChartGetter | ||
|
||
variableName string // points to the global config variable | ||
variablePath []string // path of this variable on the global config variable | ||
} | ||
|
||
var ( | ||
_ commonhandlers.Named = &DefaultCOSIController{} | ||
_ lifecycle.AfterControlPlaneInitialized = &DefaultCOSIController{} | ||
_ lifecycle.BeforeClusterUpgrade = &DefaultCOSIController{} | ||
) | ||
|
||
func New( | ||
c ctrlclient.Client, | ||
cfg *ControllerConfig, | ||
helmChartInfoGetter *config.HelmChartGetter, | ||
) *DefaultCOSIController { | ||
return &DefaultCOSIController{ | ||
client: c, | ||
config: cfg, | ||
helmChartInfoGetter: helmChartInfoGetter, | ||
variableName: v1alpha1.ClusterConfigVariableName, | ||
variablePath: []string{"addons", v1alpha1.COSIVariableName}, | ||
} | ||
} | ||
|
||
func (n *DefaultCOSIController) Name() string { | ||
return "COSIControllerHandler" | ||
} | ||
|
||
func (n *DefaultCOSIController) AfterControlPlaneInitialized( | ||
ctx context.Context, | ||
req *runtimehooksv1.AfterControlPlaneInitializedRequest, | ||
resp *runtimehooksv1.AfterControlPlaneInitializedResponse, | ||
) { | ||
commonResponse := &runtimehooksv1.CommonResponse{} | ||
n.apply(ctx, &req.Cluster, commonResponse) | ||
resp.Status = commonResponse.GetStatus() | ||
resp.Message = commonResponse.GetMessage() | ||
} | ||
|
||
func (n *DefaultCOSIController) BeforeClusterUpgrade( | ||
ctx context.Context, | ||
req *runtimehooksv1.BeforeClusterUpgradeRequest, | ||
resp *runtimehooksv1.BeforeClusterUpgradeResponse, | ||
) { | ||
commonResponse := &runtimehooksv1.CommonResponse{} | ||
n.apply(ctx, &req.Cluster, commonResponse) | ||
resp.Status = commonResponse.GetStatus() | ||
resp.Message = commonResponse.GetMessage() | ||
} | ||
|
||
func (n *DefaultCOSIController) apply( | ||
ctx context.Context, | ||
cluster *clusterv1.Cluster, | ||
resp *runtimehooksv1.CommonResponse, | ||
) { | ||
clusterKey := ctrlclient.ObjectKeyFromObject(cluster) | ||
|
||
log := ctrl.LoggerFrom(ctx).WithValues( | ||
"cluster", | ||
clusterKey, | ||
) | ||
|
||
varMap := variables.ClusterVariablesToVariablesMap(cluster.Spec.Topology.Variables) | ||
|
||
cosiVar, err := variables.Get[apivariables.COSI](varMap, n.variableName, n.variablePath...) | ||
if err != nil { | ||
if variables.IsNotFoundError(err) { | ||
log. | ||
Info( | ||
"Skipping COSI handler, cluster does not specify request COSI Controller addon deployment", | ||
) | ||
return | ||
} | ||
log.Error( | ||
err, | ||
"failed to read COSI variable from cluster definition", | ||
) | ||
resp.SetStatus(runtimehooksv1.ResponseStatusFailure) | ||
resp.SetMessage( | ||
fmt.Sprintf("failed to read COSI variable from cluster definition: %v", | ||
err, | ||
), | ||
) | ||
return | ||
} | ||
|
||
var strategy addons.Applier | ||
switch ptr.Deref(cosiVar.Strategy, "") { | ||
case v1alpha1.AddonStrategyHelmAddon: | ||
helmChart, err := n.helmChartInfoGetter.For(ctx, log, config.COSIController) | ||
if err != nil { | ||
log.Error( | ||
err, | ||
"failed to get configmap with helm settings", | ||
) | ||
resp.SetStatus(runtimehooksv1.ResponseStatusFailure) | ||
resp.SetMessage( | ||
fmt.Sprintf("failed to get configuration to create helm addon: %v", | ||
err, | ||
), | ||
) | ||
return | ||
} | ||
strategy = addons.NewHelmAddonApplier( | ||
n.config.helmAddonConfig, | ||
n.client, | ||
helmChart, | ||
) | ||
case v1alpha1.AddonStrategyClusterResourceSet: | ||
resp.SetStatus(runtimehooksv1.ResponseStatusFailure) | ||
resp.SetMessage( | ||
fmt.Sprintf( | ||
"strategy %q not provided for COSI", v1alpha1.AddonStrategyClusterResourceSet, | ||
), | ||
) | ||
return | ||
case "": | ||
resp.SetStatus(runtimehooksv1.ResponseStatusFailure) | ||
resp.SetMessage("strategy not provided for COSI") | ||
return | ||
default: | ||
resp.SetStatus(runtimehooksv1.ResponseStatusFailure) | ||
resp.SetMessage(fmt.Sprintf("unknown COSI addon deployment strategy %q", *cosiVar.Strategy)) | ||
return | ||
} | ||
|
||
if err := strategy.Apply(ctx, cluster, n.config.DefaultsNamespace(), log); err != nil { | ||
err = fmt.Errorf("failed to apply COSI addon: %w", err) | ||
resp.SetStatus(runtimehooksv1.ResponseStatusFailure) | ||
resp.SetMessage(err.Error()) | ||
return | ||
} | ||
|
||
resp.SetStatus(runtimehooksv1.ResponseStatusSuccess) | ||
} |
Oops, something went wrong.