From 9d6f6536144747aa235fc78c8d5dbba45f42935e Mon Sep 17 00:00:00 2001 From: Salah Al Saleh Date: Fri, 7 Jun 2024 15:28:21 -0700 Subject: [PATCH] Add SeaweedFS S3 service IP to backup annotations (#4669) --- pkg/embeddedcluster/util.go | 19 +++++++++++++++++++ pkg/kotsadmsnapshot/backup.go | 7 +++++++ 2 files changed, 26 insertions(+) diff --git a/pkg/embeddedcluster/util.go b/pkg/embeddedcluster/util.go index 068cf41951..e9cb5332cb 100644 --- a/pkg/embeddedcluster/util.go +++ b/pkg/embeddedcluster/util.go @@ -11,11 +11,19 @@ import ( embeddedclusterv1beta1 "github.com/replicatedhq/embedded-cluster-kinds/apis/v1beta1" "github.com/replicatedhq/kots/pkg/k8sutil" kotsv1beta1 "github.com/replicatedhq/kotskinds/apis/kots/v1beta1" + corev1 "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + k8stypes "k8s.io/apimachinery/pkg/types" "k8s.io/client-go/kubernetes" kbclient "sigs.k8s.io/controller-runtime/pkg/client" ) +const ( + seaweedfsNamespace = "seaweedfs" + seaweedfsS3SVCName = "ec-seaweedfs-s3" +) + // ErrNoInstallations is returned when no installation object is found in the cluster. var ErrNoInstallations = fmt.Errorf("no installations found") @@ -73,6 +81,17 @@ func ClusterConfig(ctx context.Context, kbClient kbclient.Client) (*embeddedclus return latest.Spec.Config, nil } +func GetSeaweedFSS3ServiceIP(ctx context.Context, kbClient kbclient.Client) (string, error) { + nsn := k8stypes.NamespacedName{Name: seaweedfsS3SVCName, Namespace: seaweedfsNamespace} + var svc corev1.Service + if err := kbClient.Get(ctx, nsn, &svc); err != nil && !errors.IsNotFound(err) { + return "", fmt.Errorf("failed to get seaweedfs s3 service: %w", err) + } else if errors.IsNotFound(err) { + return "", nil + } + return svc.Spec.ClusterIP, nil +} + func getArtifactsFromInstallation(installation kotsv1beta1.Installation, appSlug string) *embeddedclusterv1beta1.ArtifactsLocation { if installation.Spec.EmbeddedClusterArtifacts == nil { return nil diff --git a/pkg/kotsadmsnapshot/backup.go b/pkg/kotsadmsnapshot/backup.go index 96897f5a5c..cd4857399e 100644 --- a/pkg/kotsadmsnapshot/backup.go +++ b/pkg/kotsadmsnapshot/backup.go @@ -382,6 +382,13 @@ func CreateInstanceBackup(ctx context.Context, cluster *downstreamtypes.Downstre if err != nil { return nil, fmt.Errorf("failed to get current installation: %w", err) } + seaweedFSS3ServiceIP, err := embeddedcluster.GetSeaweedFSS3ServiceIP(ctx, kbClient) + if err != nil { + return nil, fmt.Errorf("failed to get seaweedfs s3 service ip: %w", err) + } + if seaweedFSS3ServiceIP != "" { + backupAnnotations["kots.io/embedded-cluster-seaweedfs-s3-ip"] = seaweedFSS3ServiceIP + } backupAnnotations["kots.io/embedded-cluster"] = "true" backupAnnotations["kots.io/embedded-cluster-id"] = util.EmbeddedClusterID() backupAnnotations["kots.io/embedded-cluster-version"] = util.EmbeddedClusterVersion()