generated from giantswarm/template-operator
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add pkg/common/monitoring/observability-bundle.go
- Loading branch information
1 parent
f1474bb
commit a3724b3
Showing
1 changed file
with
37 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
} |