Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove k8s package in favor of using k8s client directly
Browse files Browse the repository at this point in the history
phillebaba committed May 17, 2024
1 parent 75c9826 commit fc365ea
Showing 34 changed files with 937 additions and 1,627 deletions.
6 changes: 3 additions & 3 deletions src/cmd/connect.go
Original file line number Diff line number Diff line change
@@ -13,8 +13,8 @@ import (
"github.com/defenseunicorns/zarf/src/cmd/common"
"github.com/defenseunicorns/zarf/src/config/lang"
"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/pkg/tunnel"
"github.com/defenseunicorns/zarf/src/pkg/utils/exec"
"github.com/spf13/cobra"
)
@@ -45,7 +45,7 @@ var (

ctx := cmd.Context()

var tunnel *k8s.Tunnel
var tunnel *tunnel.Tunnel
if connectResourceName != "" {
zt := cluster.NewTunnelInfo(connectNamespace, connectResourceType, connectResourceName, "", connectLocalPort, connectRemotePort)
tunnel, err = c.ConnectTunnelInfo(ctx, zt)
@@ -107,7 +107,7 @@ func init() {

connectCmd.Flags().StringVar(&connectResourceName, "name", "", lang.CmdConnectFlagName)
connectCmd.Flags().StringVar(&connectNamespace, "namespace", cluster.ZarfNamespaceName, lang.CmdConnectFlagNamespace)
connectCmd.Flags().StringVar(&connectResourceType, "type", k8s.SvcResource, lang.CmdConnectFlagType)
connectCmd.Flags().StringVar(&connectResourceType, "type", tunnel.SvcResource, lang.CmdConnectFlagType)
connectCmd.Flags().IntVar(&connectLocalPort, "local-port", 0, lang.CmdConnectFlagLocalPort)
connectCmd.Flags().IntVar(&connectRemotePort, "remote-port", 0, lang.CmdConnectFlagRemotePort)
connectCmd.Flags().BoolVar(&cliOnly, "cli-only", false, lang.CmdConnectFlagCliOnly)
3 changes: 1 addition & 2 deletions src/extensions/bigbang/test/bigbang_test.go
Original file line number Diff line number Diff line change
@@ -128,8 +128,7 @@ func testConnection(ctx context.Context, t *testing.T) {
// Establish the tunnel config
c, err := cluster.NewCluster()
require.NoError(t, err)
tunnel, err := c.NewTunnel("twistlock", "svc", "twistlock-console", "", 0, 8081)
require.NoError(t, err)
tunnel := c.CreateTunnel("twistlock", "svc", "twistlock-console", "", 0, 8081)

// Establish the tunnel connection
_, err = tunnel.Connect(ctx)
15 changes: 5 additions & 10 deletions src/internal/packager/git/gitea.go
Original file line number Diff line number Diff line change
@@ -17,8 +17,8 @@ import (

"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/pkg/tunnel"
"github.com/defenseunicorns/zarf/src/types"
"k8s.io/apimachinery/pkg/runtime/schema"
)
@@ -41,7 +41,7 @@ func (g *Git) CreateReadOnlyUser(ctx context.Context) error {
}

// Establish a git tunnel to send the repo
tunnel, err := c.NewTunnel(cluster.ZarfNamespaceName, k8s.SvcResource, cluster.ZarfGitServerName, "", 0, cluster.ZarfGitServerPort)
tunnel := c.CreateTunnel(cluster.ZarfNamespaceName, tunnel.SvcResource, cluster.ZarfGitServerName, "", 0, cluster.ZarfGitServerPort)
if err != nil {
return err
}
@@ -127,11 +127,9 @@ func (g *Git) UpdateGitUser(ctx context.Context, oldAdminPass string, username s
if err != nil {
return err
}

// Establish a git tunnel to send the repo
tunnel, err := c.NewTunnel(cluster.ZarfNamespaceName, k8s.SvcResource, cluster.ZarfGitServerName, "", 0, cluster.ZarfGitServerPort)
if err != nil {
return err
}
tunnel := c.CreateTunnel(cluster.ZarfNamespaceName, tunnel.SvcResource, cluster.ZarfGitServerName, "", 0, cluster.ZarfGitServerPort)
_, err = tunnel.Connect(ctx)
if err != nil {
return err
@@ -167,10 +165,7 @@ func (g *Git) CreatePackageRegistryToken(ctx context.Context) (CreateTokenRespon
}

// Establish a git tunnel to send the repo
tunnel, err := c.NewTunnel(cluster.ZarfNamespaceName, k8s.SvcResource, cluster.ZarfGitServerName, "", 0, cluster.ZarfGitServerPort)
if err != nil {
return CreateTokenResponse{}, err
}
tunnel := c.CreateTunnel(cluster.ZarfNamespaceName, tunnel.SvcResource, cluster.ZarfGitServerName, "", 0, cluster.ZarfGitServerPort)
_, err = tunnel.Connect(ctx)
if err != nil {
return CreateTokenResponse{}, err
25 changes: 15 additions & 10 deletions src/internal/packager/helm/zarf.go
Original file line number Diff line number Diff line change
@@ -8,15 +8,16 @@ import (
"context"
"fmt"

"helm.sh/helm/v3/pkg/action"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"github.com/defenseunicorns/zarf/src/internal/packager/template"
"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/pkg/transform"
"github.com/defenseunicorns/zarf/src/pkg/utils"
"github.com/defenseunicorns/zarf/src/pkg/variables"
"github.com/defenseunicorns/zarf/src/types"
"helm.sh/helm/v3/pkg/action"
)

// UpdateZarfRegistryValues updates the Zarf registry deployment with the new state values
@@ -63,7 +64,7 @@ func (h *Helm) UpdateZarfAgentValues(ctx context.Context) error {
// Get the current agent image from one of its pods.
pods := h.cluster.WaitForPodsAndContainers(
ctx,
k8s.PodLookup{
cluster.PodLookup{
Namespace: cluster.ZarfNamespaceName,
Selector: "app=agent-hook",
},
@@ -124,13 +125,17 @@ func (h *Helm) UpdateZarfAgentValues(ctx context.Context) error {
defer spinner.Stop()

// Force pods to be recreated to get the updated secret.
err = h.cluster.DeletePods(
ctx,
k8s.PodLookup{
Namespace: cluster.ZarfNamespaceName,
Selector: "app=agent-hook",
},
)
// TODO: Are the delete options actually needed, if so why?
deleteGracePeriod := int64(0)
deletePolicy := metav1.DeletePropagationForeground
deleteOpt := metav1.DeleteOptions{
GracePeriodSeconds: &deleteGracePeriod,
PropagationPolicy: &deletePolicy,
}
listOpt := metav1.ListOptions{
LabelSelector: "app=agent-hook",
}
err = h.cluster.Clientset.CoreV1().Pods(cluster.ZarfNamespaceName).DeleteCollection(ctx, deleteOpt, listOpt)
if err != nil {
return fmt.Errorf("error recycling pods for the Zarf Agent: %w", err)
}
14 changes: 7 additions & 7 deletions src/internal/packager/images/push.go
Original file line number Diff line number Diff line change
@@ -11,9 +11,9 @@ import (

"github.com/defenseunicorns/pkg/helpers"
"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/pkg/transform"
"github.com/defenseunicorns/zarf/src/pkg/tunnel"
"github.com/defenseunicorns/zarf/src/pkg/utils"
"github.com/google/go-containerregistry/pkg/crane"
"github.com/google/go-containerregistry/pkg/logs"
@@ -48,7 +48,7 @@ func Push(ctx context.Context, cfg PushConfig) error {

var (
err error
tunnel *k8s.Tunnel
tun *tunnel.Tunnel
registryURL = cfg.RegInfo.Address
)

@@ -58,21 +58,21 @@ func Push(ctx context.Context, cfg PushConfig) error {
if err := helpers.Retry(func() error {
c, _ := cluster.NewCluster()
if c != nil {
registryURL, tunnel, err = c.ConnectToZarfRegistryEndpoint(ctx, cfg.RegInfo)
registryURL, tun, err = c.ConnectToZarfRegistryEndpoint(ctx, cfg.RegInfo)
if err != nil {
return err
}
if tunnel != nil {
defer tunnel.Close()
if tun != nil {
defer tun.Close()
}
}

progress = message.NewProgressBar(totalSize, fmt.Sprintf("Pushing %d images", len(toPush)))
pushOptions := createPushOpts(cfg, progress)

pushImage := func(img v1.Image, name string) error {
if tunnel != nil {
return tunnel.Wrap(func() error { return crane.Push(img, name, pushOptions...) })
if tun != nil {
return tun.Wrap(func() error { return crane.Push(img, name, pushOptions...) })
}

return crane.Push(img, name, pushOptions...)
Loading

0 comments on commit fc365ea

Please sign in to comment.