Skip to content

Commit

Permalink
Add SeaweedFS S3 service IP to backup annotations (#4669)
Browse files Browse the repository at this point in the history
  • Loading branch information
sgalsaleh authored Jun 7, 2024
1 parent 65e1381 commit 9d6f653
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
19 changes: 19 additions & 0 deletions pkg/embeddedcluster/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions pkg/kotsadmsnapshot/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 9d6f653

Please sign in to comment.