Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions api/v1alpha1/pluginpreset_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ type PluginPresetStatus struct {
ReadyPlugins int `json:"readyPlugins,omitempty"`
// FailedPlugins is the number of failed Plugins managed by the PluginPreset.
FailedPlugins int `json:"failedPlugins,omitempty"`
// PluginDefinitionVersion is the version of the PluginDefinition referenced by this PluginPreset.
PluginDefinitionVersion string `json:"pluginDefinitionVersion,omitempty"`
}

// ManagedPluginStatus defines the Ready condition of a managed Plugin identified by its name.
Expand All @@ -149,6 +151,7 @@ type ManagedPluginStatus struct {
//+kubebuilder:subresource:status
//+kubebuilder:resource:shortName=pp
//+kubebuilder:printcolumn:name="Plugin Definition",type=string,JSONPath=`.spec.plugin.pluginDefinitionRef.name`
//+kubebuilder:printcolumn:name="Version",type=string,JSONPath=`.status.pluginDefinitionVersion`
//+kubebuilder:printcolumn:name="Release Namespace",type=string,JSONPath=`.spec.plugin.releaseNamespace`
//+kubebuilder:printcolumn:name="Ready",type="string",JSONPath=`.status.statusConditions.conditions[?(@.type == "Ready")].status`
//+kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp"
Expand Down
7 changes: 7 additions & 0 deletions charts/manager/crds/greenhouse.sap_pluginpresets.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ spec:
- jsonPath: .spec.plugin.pluginDefinitionRef.name
name: Plugin Definition
type: string
- jsonPath: .status.pluginDefinitionVersion
name: Version
type: string
- jsonPath: .spec.plugin.releaseNamespace
name: Release Namespace
type: string
Expand Down Expand Up @@ -498,6 +501,10 @@ spec:
description: FailedPlugins is the number of failed Plugins managed
by the PluginPreset.
type: integer
pluginDefinitionVersion:
description: PluginDefinitionVersion is the version of the PluginDefinition
referenced by this PluginPreset.
type: string
pluginStatuses:
description: PluginStatuses contains statuses of Plugins managed by
the PluginPreset.
Expand Down
11 changes: 11 additions & 0 deletions docs/reference/api/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3649,6 +3649,17 @@ <h3 id="greenhouse.sap/v1alpha1.PluginPresetStatus">PluginPresetStatus
<p>FailedPlugins is the number of failed Plugins managed by the PluginPreset.</p>
</td>
</tr>
<tr>
<td>
<code>pluginDefinitionVersion</code><br>
<em>
string
</em>
</td>
<td>
<p>PluginDefinitionVersion is the version of the PluginDefinition referenced by this PluginPreset.</p>
</td>
</tr>
</tbody>
</table>
</div>
Expand Down
3 changes: 3 additions & 0 deletions docs/reference/api/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1504,6 +1504,9 @@ components:
failedPlugins:
description: FailedPlugins is the number of failed Plugins managed by the PluginPreset.
type: integer
pluginDefinitionVersion:
description: PluginDefinitionVersion is the version of the PluginDefinition referenced by this PluginPreset.
type: string
pluginStatuses:
description: PluginStatuses contains statuses of Plugins managed by the PluginPreset.
items:
Expand Down
14 changes: 14 additions & 0 deletions internal/controller/plugin/pluginpreset_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
greenhousemetav1alpha1 "github.com/cloudoperators/greenhouse/api/meta/v1alpha1"
greenhousev1alpha1 "github.com/cloudoperators/greenhouse/api/v1alpha1"
"github.com/cloudoperators/greenhouse/internal/clientutil"
"github.com/cloudoperators/greenhouse/internal/common"
"github.com/cloudoperators/greenhouse/internal/util"
"github.com/cloudoperators/greenhouse/pkg/lifecycle"
)
Expand Down Expand Up @@ -126,6 +127,8 @@ func (r *PluginPresetReconciler) EnsureCreated(ctx context.Context, resource lif

clusters = clientutil.FilterClustersBeingDeleted(clusters)

r.reconcilePluginDefinitionVersion(ctx, pluginPreset)

err = r.reconcilePluginPreset(ctx, pluginPreset, clusters)
if err != nil {
return ctrl.Result{}, lifecycle.Failed, err
Expand Down Expand Up @@ -329,6 +332,17 @@ func (r *PluginPresetReconciler) reconcilePluginStatuses(
return nil
}

// reconcilePluginDefinitionVersion fetches the referenced PluginDefinition and updates the version in the preset's status.
func (r *PluginPresetReconciler) reconcilePluginDefinitionVersion(ctx context.Context, preset *greenhousev1alpha1.PluginPreset) {
pluginDefinitionSpec, err := common.GetPluginDefinitionSpec(ctx, r.Client, preset.Spec.Plugin.PluginDefinitionRef, preset.GetNamespace())
if err != nil {
// Best-effort: clear the field to avoid reporting a stale version when the referenced definition can't be resolved.
preset.Status.PluginDefinitionVersion = ""
return
}
preset.Status.PluginDefinitionVersion = pluginDefinitionSpec.Version
}
Comment thread
Copilot marked this conversation as resolved.

func isPluginManagedByPreset(plugin *greenhousev1alpha1.Plugin, presetName string) bool {
return plugin.Labels[greenhouseapis.LabelKeyPluginPreset] == presetName
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,7 @@ var _ = Describe("PluginPreset Controller Lifecycle", Ordered, func() {
g.Expect(managedPluginStatus.PluginName).To(Equal(expectedPluginName), "managed plugin status should have the correct PluginName set")
// Note: ReadyCondition may not be true since Flux is not running, but Plugin should exist
g.Expect(testPluginPreset.Status.TotalPlugins).To(Equal(1), "PluginPreset Status should show exactly one plugin in total")
g.Expect(testPluginPreset.Status.PluginDefinitionVersion).To(Equal(pluginPresetDefinition.Spec.Version), "PluginPreset status should expose the version of the referenced PluginDefinition")
}).Should(Succeed())

By("verifying HelmRelease exists for the managed Plugin")
Expand Down
Loading