Skip to content

Commit

Permalink
refactor: remove use of k8s dynamic
Browse files Browse the repository at this point in the history
  • Loading branch information
phillebaba committed May 30, 2024
1 parent c09cac5 commit cac7723
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 96 deletions.
40 changes: 27 additions & 13 deletions src/internal/packager/git/gitea.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@ import (
"encoding/json"
"fmt"
"io"
netHttp "net/http"
"os"
"time"

netHttp "net/http"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"github.com/defenseunicorns/zarf/src/config"
"github.com/defenseunicorns/zarf/src/pkg/cluster"
"github.com/defenseunicorns/zarf/src/pkg/k8s"
"github.com/defenseunicorns/zarf/src/pkg/message"
"github.com/defenseunicorns/zarf/src/types"
"k8s.io/apimachinery/pkg/runtime/schema"
)

// CreateTokenResponse is the response given from creating a token in Gitea
Expand Down Expand Up @@ -253,24 +253,38 @@ func UpdateGiteaPVC(ctx context.Context, shouldRollBack bool) (string, error) {
}

pvcName := os.Getenv("ZARF_VAR_GIT_SERVER_EXISTING_PVC")
groupKind := schema.GroupKind{
Group: "",
Kind: "PersistentVolumeClaim",
}
labels := map[string]string{"app.kubernetes.io/managed-by": "Helm"}
annotations := map[string]string{"meta.helm.sh/release-name": "zarf-gitea", "meta.helm.sh/release-namespace": "zarf"}

if shouldRollBack {
err = c.K8s.RemoveLabelsAndAnnotations(ctx, cluster.ZarfNamespaceName, pvcName, groupKind, labels, annotations)
return "false", err
pvc, err := c.Clientset.CoreV1().PersistentVolumeClaims(cluster.ZarfNamespaceName).Get(ctx, pvcName, metav1.GetOptions{})
if err != nil {
return "false", err
}
delete(pvc.Labels, "app.kubernetes.io/managed-by")
delete(pvc.Annotations, "meta.helm.sh/release-name")
delete(pvc.Annotations, "meta.helm.sh/release-namespace")
_, err = c.Clientset.CoreV1().PersistentVolumeClaims(cluster.ZarfNamespaceName).Update(ctx, pvc, metav1.UpdateOptions{})
if err != nil {
return "false", err
}
return "false", nil
}

if pvcName == "data-zarf-gitea-0" {
err = c.K8s.AddLabelsAndAnnotations(ctx, cluster.ZarfNamespaceName, pvcName, groupKind, labels, annotations)
return "true", err
pvc, err := c.Clientset.CoreV1().PersistentVolumeClaims(cluster.ZarfNamespaceName).Get(ctx, pvcName, metav1.GetOptions{})
if err != nil {
return "false", err
}
pvc.Labels["app.kubernetes.io/managed-by"] = "Helm"
pvc.Annotations["meta.helm.sh/release-name"] = "zarf-gitea"
pvc.Annotations["meta.helm.sh/release-namespace"] = "zarf"
_, err = c.Clientset.CoreV1().PersistentVolumeClaims(cluster.ZarfNamespaceName).Update(ctx, pvc, metav1.UpdateOptions{})
if err != nil {
return "false", err
}
return "true", nil
}

return "false", err
return "false", nil
}

// DoHTTPThings adds http request boilerplate and perform the request, checking for a successful response.
Expand Down
83 changes: 0 additions & 83 deletions src/pkg/k8s/dynamic.go

This file was deleted.

0 comments on commit cac7723

Please sign in to comment.