Skip to content

Commit

Permalink
feat: Pull in CAAPH APIs (#282)
Browse files Browse the repository at this point in the history
  • Loading branch information
jimmidyson authored Jan 9, 2024
1 parent 345a7e2 commit 53c232d
Show file tree
Hide file tree
Showing 12 changed files with 1,128 additions and 109 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/*
Copyright 2022 The Kubernetes 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 v1alpha1

import clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"

// HelmChartProxy Conditions and Reasons.
const (
// HelmReleaseProxySpecsUpToDateCondition indicates that the HelmReleaseProxy specs are up to date with the HelmChartProxy specs,
// meaning that the HelmReleaseProxies are created/updated, value template parsing succeeded, and the orphaned HelmReleaseProxies are deleted.
HelmReleaseProxySpecsUpToDateCondition clusterv1.ConditionType = "HelmReleaseProxySpecsUpToDate"

// HelmReleaseProxyCreationFailedReason indicates that the HelmChartProxy controller failed to create a HelmReleaseProxy.
HelmReleaseProxyCreationFailedReason = "HelmReleaseProxyCreationFailed"

// HelmReleaseProxyDeletionFailedReason indicates that the HelmChartProxy controller failed to delete a HelmReleaseProxy.
HelmReleaseProxyDeletionFailedReason = "HelmReleaseProxyDeletionFailed"

// HelmReleaseProxyReinstallingReason indicates that the HelmChartProxy controller is reinstalling a HelmReleaseProxy.
HelmReleaseProxyReinstallingReason = "HelmReleaseProxyReinstalling"

// ValueParsingFailedReason indicates that the HelmChartProxy controller failed to parse the values.
ValueParsingFailedReason = "ValueParsingFailed"

// ClusterSelectionFailedReason indicates that the HelmChartProxy controller failed to select the workload Clusters.
ClusterSelectionFailedReason = "ClusterSelectionFailed"

// HelmReleaseProxiesReadyCondition indicates that the HelmReleaseProxies are ready, meaning that the Helm installation, upgrade
// or deletion is complete.
HelmReleaseProxiesReadyCondition clusterv1.ConditionType = "HelmReleaseProxiesReady"
)

// HelmReleaseProxy Conditions and Reasons.
const (
// HelmReleaseReadyCondition indicates the current status of the underlying Helm release managed by the HelmReleaseProxy.
HelmReleaseReadyCondition clusterv1.ConditionType = "HelmReleaseReady"

// PreparingToHelmInstallReason indicates that the HelmReleaseProxy is preparing to install the Helm release.
PreparingToHelmInstallReason = "PreparingToHelmInstall"

// HelmReleasePendingReason indicates that the HelmReleaseProxy is pending either install, upgrade, or rollback.
HelmReleasePendingReason = "HelmReleasePending"

// HelmInstallOrUpgradeFailedReason indicates that the HelmReleaseProxy failed to install or upgrade the Helm release.
HelmInstallOrUpgradeFailedReason = "HelmInstallOrUpgradeFailed"

// HelmReleaseDeletionFailedReason is indicates that the HelmReleaseProxy failed to delete the Helm release.
HelmReleaseDeletionFailedReason = "HelmReleaseDeletionFailed"

// HelmReleaseDeletedReason indicates that the HelmReleaseProxy deleted the Helm release.
HelmReleaseDeletedReason = "HelmReleaseDeleted"

// HelmReleaseGetFailedReason indicates that the HelmReleaseProxy failed to get the Helm release.
HelmReleaseGetFailedReason = "HelmReleaseGetFailed"

// ClusterAvailableCondition indicates that the Cluster to install the Helm release on is available.
ClusterAvailableCondition clusterv1.ConditionType = "ClusterAvailable"

// GetClusterFailedReason indicates that the HelmReleaseProxy failed to get the Cluster.
GetClusterFailedReason = "GetClusterFailed"

// GetKubeconfigFailedReason indicates that the HelmReleaseProxy failed to get the kubeconfig for the Cluster.
GetKubeconfigFailedReason = "GetKubeconfigFailed"
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
Copyright 2022 The Kubernetes 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 v1alpha1 contains API Schema definitions for the addons v1alpha1 API group
// +kubebuilder:object:generate=true
// +groupName=addons.cluster.x-k8s.io
package v1alpha1

import (
"k8s.io/apimachinery/pkg/runtime/schema"
"sigs.k8s.io/controller-runtime/pkg/scheme"
)

var (
// GroupVersion is group version used to register these objects.
GroupVersion = schema.GroupVersion{Group: "addons.cluster.x-k8s.io", Version: "v1alpha1"}

// SchemeBuilder is used to add go types to the GroupVersionKind scheme.
SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion}

// AddToScheme adds the types in this group-version to the given scheme.
AddToScheme = SchemeBuilder.AddToScheme
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,243 @@
/*
Copyright 2022 The Kubernetes 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 v1alpha1

import (
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
)

const (
// HelmChartProxyFinalizer is the finalizer used by the HelmChartProxy controller to cleanup add-on resources when
// a HelmChartProxy is being deleted.
HelmChartProxyFinalizer = "helmchartproxy.addons.cluster.x-k8s.io"
)

// HelmChartProxySpec defines the desired state of HelmChartProxy.
type HelmChartProxySpec struct {
// ClusterSelector selects Clusters in the same namespace with a label that matches the specified label selector. The Helm
// chart will be installed on all selected Clusters. If a Cluster is no longer selected, the Helm release will be uninstalled.
ClusterSelector metav1.LabelSelector `json:"clusterSelector"`

// ChartName is the name of the Helm chart in the repository.
// e.g. chart-path oci://repo-url/chart-name as chartName: chart-name and https://repo-url/chart-name as chartName: chart-name
ChartName string `json:"chartName"`

// RepoURL is the URL of the Helm chart repository.
// e.g. chart-path oci://repo-url/chart-name as repoURL: oci://repo-url and https://repo-url/chart-name as repoURL: https://repo-url
RepoURL string `json:"repoURL"`

// ReleaseName is the release name of the installed Helm chart. If it is not specified, a name will be generated.
// +optional
ReleaseName string `json:"releaseName,omitempty"`

// ReleaseNamespace is the namespace the Helm release will be installed on each selected
// Cluster. If it is not specified, it will be set to the default namespace.
// +optional
ReleaseNamespace string `json:"namespace,omitempty"`

// Version is the version of the Helm chart. If it is not specified, the chart will use
// and be kept up to date with the latest version.
// +optional
Version string `json:"version,omitempty"`

// ValuesTemplate is an inline YAML representing the values for the Helm chart. This YAML supports Go templating to reference
// fields from each selected workload Cluster and programatically create and set values.
// +optional
ValuesTemplate string `json:"valuesTemplate,omitempty"`

// Options represents CLI flags passed to Helm operations (i.e. install, upgrade, delete) and
// include options such as wait, skipCRDs, timeout, waitForJobs, etc.
// +optional
Options *HelmOptions `json:"options,omitempty"`
}

type HelmOptions struct {
// DisableHooks prevents hooks from running during the Helm install action.
// +optional
DisableHooks bool `json:"disableHooks,omitempty"`

// Wait enables the waiting for resources to be ready after a Helm install/upgrade has been performed.
// +optional
Wait bool `json:"wait,omitempty"`

// WaitForJobs enables waiting for jobs to complete after a Helm install/upgrade has been performed.
// +optional
WaitForJobs bool `json:"waitForJobs,omitempty"`

// DependencyUpdate indicates the Helm install/upgrade action to get missing dependencies.
// +optional
DependencyUpdate bool `json:"dependencyUpdate,omitempty"`

// Timeout is the time to wait for any individual Kubernetes operation (like
// resource creation, Jobs for hooks, etc.) during the performance of a Helm install action.
// Defaults to '10 min'.
// +optional
Timeout *metav1.Duration `json:"timeout,omitempty"`

// SkipCRDs controls whether CRDs should be installed during install/upgrade operation.
// By default, CRDs are installed if not already present.
// If set, no CRDs will be installed.
// +optional
SkipCRDs bool `json:"skipCRDs,omitempty"`

// SubNotes determines whether sub-notes should be rendered in the chart.
// +optional
SubNotes bool `json:"options,omitempty"`

// DisableOpenAPIValidation controls whether OpenAPI validation is enforced.
// +optional
DisableOpenAPIValidation bool `json:"disableOpenAPIValidation,omitempty"`

// Atomic indicates the installation/upgrade process to delete the installation or rollback on failure.
// If 'Atomic' is set, wait will be enabled automatically during helm install/upgrade operation.
// +optional
Atomic bool `json:"atomic,omitempty"`

// Install represents CLI flags passed to Helm install operation which can be used to control
// behaviour of helm Install operations via options like wait, skipCrds, timeout, waitForJobs, etc.
// +optional
Install *HelmInstallOptions `json:"install,omitempty"`

// Upgrade represents CLI flags passed to Helm upgrade operation which can be used to control
// behaviour of helm Upgrade operations via options like wait, skipCrds, timeout, waitForJobs, etc.
// +optional
Upgrade *HelmUpgradeOptions `json:"upgrade,omitempty"`

// Uninstall represents CLI flags passed to Helm uninstall operation which can be used to control
// behaviour of helm Uninstall operation via options like wait, timeout, etc.
// +optional
Uninstall *HelmUninstallOptions `json:"uninstall,omitempty"`
}

type HelmInstallOptions struct {
// CreateNamespace indicates the Helm install/upgrade action to create the
// HelmChartProxySpec.ReleaseNamespace if it does not exist yet.
// On uninstall, the namespace will not be garbage collected.
// If it is not specified by user, will be set to default 'true'.
// +optional
CreateNamespace *bool `json:"createNamespace,omitempty"`

// IncludeCRDs determines whether CRDs stored as a part of helm templates directory should be installed.
// +optional
IncludeCRDs bool `json:"includeCRDs,omitempty"`
}

type HelmUpgradeOptions struct {
// Force indicates to ignore certain warnings and perform the helm release upgrade anyway.
// This should be used with caution.
// +optional
Force bool `json:"force,omitempty"`

// ResetValues will reset the values to the chart's built-ins rather than merging with existing.
// +optional
ResetValues bool `json:"resetValues,omitempty"`

// ReuseValues will re-use the user's last supplied values.
// +optional
ReuseValues bool `json:"reuseValues,omitempty"`

// Recreate will (if true) recreate pods after a rollback.
// +optional
Recreate bool `json:"recreate,omitempty"`

// MaxHistory limits the maximum number of revisions saved per release
// +optional
MaxHistory int `json:"maxHistory,omitempty"`

// CleanupOnFail indicates the upgrade action to delete newly-created resources on a failed update operation.
// +optional
CleanupOnFail bool `json:"cleanupOnFail,omitempty"`
}

type HelmUninstallOptions struct {
// KeepHistory defines whether historical revisions of a release should be saved.
// If it's set, helm uninstall operation will not delete the history of the release.
// The helm storage backend (secret, configmap, etc) will be retained in the cluster.
// +optional
KeepHistory bool `json:"keepHistory,omitempty"`

// Description represents human readable information to be shown on release uninstall.
// +optional
Description string `json:"description,omitempty"`
}

// HelmChartProxyStatus defines the observed state of HelmChartProxy.
type HelmChartProxyStatus struct {
// Conditions defines current state of the HelmChartProxy.
// +optional
Conditions clusterv1.Conditions `json:"conditions,omitempty"`

// MatchingClusters is the list of references to Clusters selected by the ClusterSelector.
// +optional
MatchingClusters []corev1.ObjectReference `json:"matchingClusters"`
}

// +kubebuilder:object:root=true
// +kubebuilder:subresource:status
// +kubebuilder:printcolumn:name="Ready",type="string",JSONPath=".status.conditions[?(@.type=='Ready')].status"
// +kubebuilder:printcolumn:name="Reason",type="string",JSONPath=".status.conditions[?(@.type=='Ready')].reason"
// +kubebuilder:printcolumn:name="Message",type="string",priority=1,JSONPath=".status.conditions[?(@.type=='Ready')].message"
// +kubebuilder:resource:shortName=hcp

// HelmChartProxy is the Schema for the helmchartproxies API.
type HelmChartProxy struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec HelmChartProxySpec `json:"spec,omitempty"`
Status HelmChartProxyStatus `json:"status,omitempty"`
}

//+kubebuilder:object:root=true

// HelmChartProxyList contains a list of HelmChartProxy.
type HelmChartProxyList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []HelmChartProxy `json:"items"`
}

// GetConditions returns the list of conditions for an HelmChartProxy API object.
func (c *HelmChartProxy) GetConditions() clusterv1.Conditions {
return c.Status.Conditions
}

// SetConditions will set the given conditions on an HelmChartProxy object.
func (c *HelmChartProxy) SetConditions(conditions clusterv1.Conditions) {
c.Status.Conditions = conditions
}

// SetMatchingClusters will set the given list of matching clusters on an HelmChartProxy object.
func (c *HelmChartProxy) SetMatchingClusters(clusterList []clusterv1.Cluster) {
matchingClusters := make([]corev1.ObjectReference, 0, len(clusterList))
for _, cluster := range clusterList {
matchingClusters = append(matchingClusters, corev1.ObjectReference{
Kind: cluster.Kind,
APIVersion: cluster.APIVersion,
Name: cluster.Name,
Namespace: cluster.Namespace,
})
}

c.Status.MatchingClusters = matchingClusters
}

func init() {
SchemeBuilder.Register(&HelmChartProxy{}, &HelmChartProxyList{})
}
Loading

0 comments on commit 53c232d

Please sign in to comment.