Skip to content

Commit

Permalink
Merge branch 'main' into feat/dex-sql
Browse files Browse the repository at this point in the history
  • Loading branch information
abhijith-darshan committed Feb 7, 2025
2 parents 55e946c + 6564bc5 commit 7ec3a48
Show file tree
Hide file tree
Showing 21 changed files with 64 additions and 933 deletions.
2 changes: 1 addition & 1 deletion charts/greenhouse/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ apiVersion: v2
name: greenhouse
description: A Helm chart for deploying greenhouse
type: application
version: 0.7.1
version: 0.7.2
appVersion: "0.1.0"

dependencies:
Expand Down
3 changes: 3 additions & 0 deletions charts/greenhouse/templates/plugin-ingress-nginx.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ spec:
value: true
- name: controller.scope.enabled
value: false
- name: controller.config
value:
allow-cross-namespace-resources: true
{{ if .Values.ingress.loadBalancerIP }}
- name: controller.service.loadBalancerIP
value: {{ .Values.ingress.loadBalancerIP | quote }}
Expand Down
5 changes: 2 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ replace (
k8s.io/client-go => k8s.io/client-go v0.31.5
k8s.io/component-base => k8s.io/component-base v0.31.5
k8s.io/kubectl => k8s.io/kubectl v0.31.5
sigs.k8s.io/controller-runtime => sigs.k8s.io/controller-runtime v0.19.4
sigs.k8s.io/controller-runtime => sigs.k8s.io/controller-runtime v0.19.5
)

require (
Expand Down Expand Up @@ -44,8 +44,7 @@ require (
k8s.io/client-go v0.31.5
k8s.io/kubectl v0.31.5
k8s.io/utils v0.0.0-20241210054802-24370beab758
sigs.k8s.io/controller-runtime v0.19.4
sigs.k8s.io/e2e-framework v0.5.0
sigs.k8s.io/controller-runtime v0.19.5
sigs.k8s.io/kind v0.26.0
sigs.k8s.io/yaml v1.4.0
)
Expand Down
6 changes: 2 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -722,10 +722,8 @@ k8s.io/utils v0.0.0-20241210054802-24370beab758 h1:sdbE21q2nlQtFh65saZY+rRM6x6aJ
k8s.io/utils v0.0.0-20241210054802-24370beab758/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0=
oras.land/oras-go v1.2.6 h1:z8cmxQXBU8yZ4mkytWqXfo6tZcamPwjsuxYU81xJ8Lk=
oras.land/oras-go v1.2.6/go.mod h1:OVPc1PegSEe/K8YiLfosrlqlqTN9PUyFvOw5Y9gwrT8=
sigs.k8s.io/controller-runtime v0.19.4 h1:SUmheabttt0nx8uJtoII4oIP27BVVvAKFvdvGFwV/Qo=
sigs.k8s.io/controller-runtime v0.19.4/go.mod h1:iRmWllt8IlaLjvTTDLhRBXIEtkCK6hwVBJJsYS9Ajf4=
sigs.k8s.io/e2e-framework v0.5.0 h1:YLhk8R7EHuTFQAe6Fxy5eBzn5Vb+yamR5u8MH1Rq3cE=
sigs.k8s.io/e2e-framework v0.5.0/go.mod h1:jJSH8u2RNmruekUZgHAtmRjb5Wj67GErli9UjLSY7Zc=
sigs.k8s.io/controller-runtime v0.19.5 h1:rsE2cRYe0hK/rAAwiS1bwqgEcgCxTz9lavs3FMgLW0c=
sigs.k8s.io/controller-runtime v0.19.5/go.mod h1:iRmWllt8IlaLjvTTDLhRBXIEtkCK6hwVBJJsYS9Ajf4=
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd h1:EDPBXCAspyGV4jQlpZSudPeMmr1bNJefnuqLsRAsHZo=
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd/go.mod h1:B8JuhiUyNFVKdsE8h686QcCxMaH6HrOAZj4vswFpcB0=
sigs.k8s.io/kind v0.26.0 h1:8fS6I0Q5WGlmLprSpH0DarlOSdcsv0txnwc93J2BP7M=
Expand Down
35 changes: 0 additions & 35 deletions pkg/clientutil/finalizer.go

This file was deleted.

2 changes: 1 addition & 1 deletion pkg/controllers/plugin/helm_chart_testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func (r *PluginReconciler) reconcileHelmChartTest(ctx context.Context, plugin *g
return &reconcileResult{requeueAfter: result.requeueAfter}, nil
}

hasHelmChartTest, err := helm.HelmChartTest(ctx, restClientGetter, plugin)
hasHelmChartTest, err := helm.ChartTest(restClientGetter, plugin)
prometheusLabels := prometheus.Labels{
"cluster": plugin.Spec.ClusterName,
"plugin": plugin.Name,
Expand Down
6 changes: 4 additions & 2 deletions pkg/controllers/plugin/plugin_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,9 @@ func (r *PluginReconciler) SetupWithManager(name string, mgr ctrl.Manager) error
WithOptions(controller.Options{
RateLimiter: workqueue.NewTypedMaxOfRateLimiter(
workqueue.NewTypedItemExponentialFailureRateLimiter[reconcile.Request](30*time.Second, 1*time.Hour),
&workqueue.TypedBucketRateLimiter[reconcile.Request]{Limiter: rate.NewLimiter(rate.Limit(10), 100)})}).
&workqueue.TypedBucketRateLimiter[reconcile.Request]{Limiter: rate.NewLimiter(rate.Limit(10), 100)}),
MaxConcurrentReconciles: 3,
}).
For(&greenhousev1alpha1.Plugin{}).
// If the release was (manually) modified the secret would have been modified. Reconcile it.
Watches(&corev1.Secret{},
Expand Down Expand Up @@ -168,7 +170,7 @@ func (r *PluginReconciler) EnsureCreated(ctx context.Context, resource lifecycle

reconcileErr := r.reconcileHelmRelease(ctx, restClientGetter, plugin, pluginDefinition)

// PluginStatus, WorkloadStatus and HelmChartTest should be reconciled regardless of Helm reconciliation result.
// PluginStatus, WorkloadStatus and ChartTest should be reconciled regardless of Helm reconciliation result.
r.reconcileStatus(ctx, restClientGetter, plugin, pluginDefinition, &plugin.Status)

workloadStatusResult, workloadStatusErr := r.reconcilePluginWorkloadStatus(ctx, restClientGetter, plugin, pluginDefinition)
Expand Down
7 changes: 6 additions & 1 deletion pkg/controllers/propagation_reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,12 @@ func (r *PropagationReconciler) Reconcile(ctx context.Context, req ctrl.Request)
return ctrl.Result{}, err
}
}
if err := clientutil.RemoveFinalizer(ctx, r.Client, obj, greenhouseapis.FinalizerCleanupPropagatedResource); err != nil {

_, err := clientutil.Patch(ctx, r.Client, obj, func() error {
controllerutil.RemoveFinalizer(obj, greenhouseapis.FinalizerCleanupPropagatedResource)
return nil
})
if err != nil {
return ctrl.Result{}, err
}

Expand Down
21 changes: 13 additions & 8 deletions pkg/helm/helm.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ var (

// IsHelmDebug is configured via a flag and enables extensive debug logging for Helm actions.
IsHelmDebug bool

// greenhouse helm timeout for install and upgrade actions
installUpgradeTimeout = 300 * time.Second
)

// driftDetectionInterval is the interval after which a drift detection is performed.
Expand Down Expand Up @@ -81,7 +84,7 @@ func InstallOrUpgradeHelmChartFromPlugin(ctx context.Context, local client.Clien
// Avoid attempts to upgrade a failed release and attempt to resurrect it.
if latestRelease.Info != nil && latestRelease.Info.Status == release.StatusFailed {
log.FromContext(ctx).Info("attempting to reset release status", "current status", latestRelease.Info.Status.String())
if err := ResetHelmReleaseStatusToDeployed(ctx, restClientGetter, plugin); err != nil {
if err := ResetHelmReleaseStatusToDeployed(restClientGetter, plugin); err != nil {
metrics.UpdateMetrics(plugin, metrics.MetricResultError, metrics.MetricReasonUpgradeFailed)
return err
}
Expand Down Expand Up @@ -112,8 +115,8 @@ func InstallOrUpgradeHelmChartFromPlugin(ctx context.Context, local client.Clien
return nil
}

// HelmChartTest to do helm test on the plugin
func HelmChartTest(ctx context.Context, restClientGetter genericclioptions.RESTClientGetter, plugin *greenhousev1alpha1.Plugin) (bool, error) {
// ChartTest to do helm test on the plugin
func ChartTest(restClientGetter genericclioptions.RESTClientGetter, plugin *greenhousev1alpha1.Plugin) (bool, error) {
var hasTestHook bool
cfg, err := newHelmAction(restClientGetter, plugin.Spec.ReleaseNamespace)
if err != nil {
Expand Down Expand Up @@ -231,7 +234,7 @@ func DiffChartToDeployedResources(ctx context.Context, local client.Client, rest
}

// ResetHelmReleaseStatusToDeployed resets the status of the release to deployed using a rollback.
func ResetHelmReleaseStatusToDeployed(ctx context.Context, restClientGetter genericclioptions.RESTClientGetter, plugin *greenhousev1alpha1.Plugin) error {
func ResetHelmReleaseStatusToDeployed(restClientGetter genericclioptions.RESTClientGetter, plugin *greenhousev1alpha1.Plugin) error {
r, err := getLatestUpgradeableRelease(restClientGetter, plugin)
if err != nil {
return err
Expand Down Expand Up @@ -353,6 +356,7 @@ func upgradeRelease(ctx context.Context, local client.Client, restClientGetter g
upgradeAction.Namespace = plugin.Spec.ReleaseNamespace
upgradeAction.DependencyUpdate = true
upgradeAction.MaxHistory = 5
upgradeAction.Timeout = installUpgradeTimeout // set a timeout for the upgrade to not be stuck in pending state
upgradeAction.Description = pluginDefinition.Spec.Version

helmChart, err := loadHelmChart(&upgradeAction.ChartPathOptions, pluginDefinition.Spec.HelmChart, settings)
Expand All @@ -365,7 +369,7 @@ func upgradeRelease(ctx context.Context, local client.Client, restClientGetter g
return err
}

helmValues, err := getValuesForHelmChart(ctx, local, helmChart, plugin, false)
helmValues, err := getValuesForHelmChart(ctx, local, helmChart, plugin)
if err != nil {
return err
}
Expand All @@ -390,6 +394,7 @@ func installRelease(ctx context.Context, local client.Client, restClientGetter g
installAction := action.NewInstall(cfg)
installAction.ReleaseName = plugin.Name
installAction.Namespace = plugin.Spec.ReleaseNamespace
installAction.Timeout = installUpgradeTimeout // set a timeout for the installation to not be stuck in pending state
installAction.CreateNamespace = true
installAction.DependencyUpdate = true
installAction.DryRun = isDryRun
Expand All @@ -409,7 +414,7 @@ func installRelease(ctx context.Context, local client.Client, restClientGetter g
if err := replaceCustomResourceDefinitions(ctx, c, helmChart.CRDObjects(), false); err != nil {
return nil, err
}
helmValues, err := getValuesForHelmChart(ctx, local, helmChart, plugin, isDryRun)
helmValues, err := getValuesForHelmChart(ctx, local, helmChart, plugin)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -517,9 +522,9 @@ func mergeMaps(a, b map[string]interface{}) map[string]interface{} {

// getValuesForHelmChart returns a set of values to be used for Helm operations.
// The order is important as the values defined in the Helm chart can be overridden by the values defined in the Plugin.
func getValuesForHelmChart(ctx context.Context, c client.Client, helmChart *chart.Chart, plugin *greenhousev1alpha1.Plugin, isDryRun bool) (map[string]interface{}, error) {
func getValuesForHelmChart(ctx context.Context, c client.Client, helmChart *chart.Chart, plugin *greenhousev1alpha1.Plugin) (map[string]interface{}, error) {
// Copy the values from the Helm chart ensuring a non-nil map.
helmValues := mergeMaps(make(map[string]interface{}, 0), helmChart.Values)
helmValues := mergeMaps(make(map[string]interface{}), helmChart.Values)
// Get values defined in plugin.
pluginValues, err := getValuesFromPlugin(ctx, c, plugin)
if err != nil {
Expand Down
12 changes: 6 additions & 6 deletions pkg/helm/helm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ var _ = Describe("helm package test", func() {
When("getting the values for the Helm chart of a plugin", func() {
It("should correctly get regular values and overwrite helm values", func() {
plugin.Spec.OptionValues = []greenhousesapv1alpha1.PluginOptionValue{*optionValue}
helmValues, err := helm.ExportGetValuesForHelmChart(context.Background(), test.K8sClient, helmChart, plugin, true)
helmValues, err := helm.ExportGetValuesForHelmChart(context.Background(), test.K8sClient, helmChart, plugin)
Expect(err).ShouldNot(HaveOccurred(),
"there should be no error getting the values")
Expect(helmValues).ShouldNot(BeNil(),
Expand All @@ -50,7 +50,7 @@ var _ = Describe("helm package test", func() {
Expect(test.K8sClient.Create(test.Ctx, pluginSecret, &client.CreateOptions{})).
Should(Succeed(), "creating an secret should be successful")

helmValues, err := helm.ExportGetValuesForHelmChart(context.Background(), test.K8sClient, helmChart, plugin, true)
helmValues, err := helm.ExportGetValuesForHelmChart(context.Background(), test.K8sClient, helmChart, plugin)
Expect(err).ShouldNot(HaveOccurred(),
"there should be no error getting the values")
Expect(helmValues).ShouldNot(BeNil(),
Expand Down Expand Up @@ -136,7 +136,7 @@ var _ = Describe("helm package test", func() {
})
})

When("handling a helm chart with CRDs", func() {
When("handling a helm chart with CRDs", Ordered, func() {
It("should re-create CRDs from Helm chart when CRD is missing on upgrade", func() {
By("installing helm chart")
err := helm.InstallOrUpgradeHelmChartFromPlugin(test.Ctx, test.K8sClient, test.RestClientGetter, testPluginWithHelmChartCRDs, plugin)
Expand Down Expand Up @@ -246,7 +246,7 @@ var _ = Describe("helm package test", func() {

var _ = DescribeTable("getting helm values from Plugin", func(defaultValue any, exp any) {
helmChart := &chart.Chart{
Values: make(map[string]interface{}, 0),
Values: make(map[string]interface{}),
}

pluginWithOptionValue := &greenhousesapv1alpha1.Plugin{
Expand All @@ -265,7 +265,7 @@ var _ = DescribeTable("getting helm values from Plugin", func(defaultValue any,
},
}

helmValues, err := helm.ExportGetValuesForHelmChart(context.Background(), test.K8sClient, helmChart, pluginWithOptionValue, true)
helmValues, err := helm.ExportGetValuesForHelmChart(context.Background(), test.K8sClient, helmChart, pluginWithOptionValue)
Expect(err).ShouldNot(HaveOccurred(),
"there should be no error getting the values")
Expect(helmValues).ShouldNot(BeNil(),
Expand Down Expand Up @@ -371,7 +371,7 @@ var _ = Describe("Plugin option checksum", Ordered, func() {
Value: test.MustReturnJSONFor("pluginValue1"),
},
}
optionValuesEmpty = []greenhousesapv1alpha1.PluginOptionValue{}
optionValuesEmpty []greenhousesapv1alpha1.PluginOptionValue
)

BeforeAll(func() {
Expand Down
28 changes: 26 additions & 2 deletions pkg/lifecycle/reconcile.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func Reconcile(ctx context.Context, kubeClient client.Client, namespacedName typ

// check whether finalizer is set
if !shouldBeDeleted && !hasFinalizer {
return ctrl.Result{}, clientutil.EnsureFinalizer(ctx, kubeClient, runtimeObject, CommonCleanupFinalizer)
return ctrl.Result{}, ensureFinalizer(ctx, kubeClient, runtimeObject, CommonCleanupFinalizer)
}

var (
Expand All @@ -88,7 +88,7 @@ func Reconcile(ctx context.Context, kubeClient client.Client, namespacedName typ
// check if the resource is already deleted (a control state to decide whether to remove finalizer)
// at this point the remote resource is already cleaned up so garbage collection can be done
if isResourceDeleted(runtimeObject) {
err = clientutil.RemoveFinalizer(ctx, kubeClient, runtimeObject, CommonCleanupFinalizer)
err = removeFinalizer(ctx, kubeClient, runtimeObject, CommonCleanupFinalizer)
return ctrl.Result{}, client.IgnoreNotFound(err)
}
// if the resource is not deleted yet, we need to ensure it is deleted
Expand Down Expand Up @@ -182,3 +182,27 @@ func patchStatus(ctx context.Context, kubeClient client.Client, newObject Runtim
}
return reconcileError
}

// ensureFinalizer - ensures a finalizer is present on the object. Returns an error on failure.
func ensureFinalizer(ctx context.Context, c client.Client, o client.Object, finalizer string) error {
if controllerutil.ContainsFinalizer(o, finalizer) {
return nil
}
_, err := clientutil.Patch(ctx, c, o, func() error {
controllerutil.AddFinalizer(o, finalizer)
return nil
})
return err
}

// removeFinalizer - removes a finalizer from an object. Returns an error on failure.
func removeFinalizer(ctx context.Context, c client.Client, o client.Object, finalizer string) error {
if !controllerutil.ContainsFinalizer(o, finalizer) {
return nil
}
_, err := clientutil.Patch(ctx, c, o, func() error {
controllerutil.RemoveFinalizer(o, finalizer)
return nil
})
return err
}
64 changes: 0 additions & 64 deletions test/e2e/README.md

This file was deleted.

Loading

0 comments on commit 7ec3a48

Please sign in to comment.