Skip to content

Commit

Permalink
making requested changes for crane ls to use FQDN for internal
Browse files Browse the repository at this point in the history
  • Loading branch information
dgershman committed Jun 22, 2023
1 parent a274b90 commit d2a85c7
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/cmd/tools/crane.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package tools

import (
"fmt"
"github.com/defenseunicorns/zarf/src/config"
"github.com/defenseunicorns/zarf/src/config/lang"
"github.com/defenseunicorns/zarf/src/internal/cluster"
Expand Down Expand Up @@ -106,16 +107,23 @@ func zarfCraneList(cranePlatformOptions *[]crane.Option) *cobra.Command {
message.Fatal(nil, lang.CmdToolsCraneListNoRepoSpecified)
}

if !strings.HasPrefix(args[0], "internal/") {
// Try to connect to a Zarf initialized cluster otherwise then pass it down to crane.
zarfCluster, err := cluster.NewCluster()
if err != nil {
return originalListFn(cmd, args)
}

// Load Zarf state
zarfState, err := cluster.NewClusterOrDie().LoadZarfState()
// Load the state
zarfState, err := zarfCluster.LoadZarfState()
if err != nil {
return err
}

// Check to see if it matches the existing internal address.
if !strings.HasPrefix(args[0], zarfState.RegistryInfo.Address) {
return originalListFn(cmd, args)
}

// Open a tunnel to the Zarf registry
tunnelReg, err := cluster.NewZarfTunnel()
if err != nil {
Expand All @@ -131,7 +139,8 @@ func zarfCraneList(cranePlatformOptions *[]crane.Option) *cobra.Command {
*cranePlatformOptions = append(*cranePlatformOptions, authOption)
registryEndpoint := tunnelReg.Endpoint()

return originalListFn(cmd, []string{strings.Replace(args[0], "internal/", registryEndpoint+"/", 1)})
return originalListFn(cmd, []string{strings.Replace(args[0],
fmt.Sprintf("%s/", zarfState.RegistryInfo.Address), fmt.Sprintf("%s/", registryEndpoint), 1)})
}

return craneList
Expand Down

0 comments on commit d2a85c7

Please sign in to comment.