From a3724b30a051fb1b11f60da26185b5704674843c Mon Sep 17 00:00:00 2001 From: Theo Brigitte Date: Mon, 12 Aug 2024 12:35:50 +0200 Subject: [PATCH] add pkg/common/monitoring/observability-bundle.go --- pkg/common/monitoring/observability-bundle.go | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 pkg/common/monitoring/observability-bundle.go diff --git a/pkg/common/monitoring/observability-bundle.go b/pkg/common/monitoring/observability-bundle.go new file mode 100644 index 00000000..c66e4a00 --- /dev/null +++ b/pkg/common/monitoring/observability-bundle.go @@ -0,0 +1,37 @@ +package monitoring + +import ( + "context" + "fmt" + + "github.com/blang/semver" + appv1 "github.com/giantswarm/apiextensions-application/api/v1alpha1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/types" + clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" + "sigs.k8s.io/controller-runtime/pkg/client" +) + +const ObservabilityBundleAppName string = "observability-bundle" + +// ObservabilityBundleAppMeta returns metadata for the observability bundle app. +func ObservabilityBundleAppMeta(cluster *clusterv1.Cluster) metav1.ObjectMeta { + metadata := metav1.ObjectMeta{ + Name: fmt.Sprintf("%s-%s", cluster.GetName(), ObservabilityBundleAppName), + Namespace: cluster.GetNamespace(), + } + + return metadata +} + +func GetObservabilityBundleAppVersion(cluster *clusterv1.Cluster, client client.Client, ctx context.Context) (version semver.Version, err error) { + // Get observability bundle app metadata. + appMeta := ObservabilityBundleAppMeta(cluster) + // Retrieve the app. + var currentApp appv1.App + err = client.Get(ctx, types.NamespacedName{Name: appMeta.GetName(), Namespace: appMeta.GetNamespace()}, ¤tApp) + if err != nil { + return version, err + } + return semver.Parse(currentApp.Spec.Version) +}