Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: remove k8s package in favor of using k8s client directly #2513

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/cmd/connect.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
3 changes: 1 addition & 2 deletions src/extensions/bigbang/test/bigbang_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
15 changes: 5 additions & 10 deletions src/internal/packager/git/gitea.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -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
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
25 changes: 15 additions & 10 deletions src/internal/packager/helm/zarf.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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",
},
Expand Down Expand Up @@ -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)
}
Expand Down
14 changes: 7 additions & 7 deletions src/internal/packager/images/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
)

Expand All @@ -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...)
Expand Down
Loading
Loading