Skip to content

Commit

Permalink
Merge branch 'main' into refactor/proxy
Browse files Browse the repository at this point in the history
  • Loading branch information
schristoff authored Aug 6, 2024
2 parents c022382 + 1ed0dab commit f0981a0
Show file tree
Hide file tree
Showing 87 changed files with 684 additions and 573 deletions.
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ module github.com/zarf-dev/zarf

go 1.22.4

replace github.com/zarf-dev/zarf/src/api => ./src/api

// TODO (@AABRO): Pending merge into github.com/gojsonschema/gojsonschema (https://github.com/gojsonschema/gojsonschema/pull/5)
replace github.com/xeipuuv/gojsonschema => github.com/defenseunicorns/gojsonschema v0.0.0-20231116163348-e00f069122d6

Expand Down Expand Up @@ -49,6 +51,7 @@ require (
github.com/spf13/viper v1.18.2
github.com/stretchr/testify v1.9.0
github.com/xeipuuv/gojsonschema v1.2.0
github.com/zarf-dev/zarf/src/api v0.0.0-00010101000000-000000000000
golang.org/x/crypto v0.25.0
golang.org/x/sync v0.7.0
golang.org/x/term v0.22.0
Expand Down
10 changes: 5 additions & 5 deletions site/src/content/docs/commands/zarf_connect.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ zarf connect { REGISTRY | GIT | connect-name } [flags]
```
--cli-only Disable browser auto-open
-h, --help help for connect
--local-port int (Optional, autogenerated if not provided) Specify the local port to bind to. E.g. local-port=42000. Ignored if --name is unset.
--name string Specify the resource name. E.g. name=unicorns or name=unicorn-pod-7448499f4d-b5bk6.
--namespace string Specify the namespace. E.g. namespace=default. Ignored if --name is unset. (default "zarf")
--remote-port int Specify the remote port of the resource to bind to. E.g. remote-port=8080. Ignored if --name is unset.
--type string Specify the resource type. E.g. type=svc or type=pod. Ignored if --name is unset. (default "svc")
--local-port int (Optional, autogenerated if not provided) Specify the local port to bind to. E.g. local-port=42000.
--name string Specify the resource name. E.g. name=unicorns or name=unicorn-pod-7448499f4d-b5bk6. Ignored if connect-name is supplied.
--namespace string Specify the namespace. E.g. namespace=default. Ignored if connect-name is supplied. (default "zarf")
--remote-port int Specify the remote port of the resource to bind to. E.g. remote-port=8080. Ignored if connect-name is supplied.
--type string Specify the resource type. E.g. type=svc or type=pod. Ignored if connect-name is supplied. (default "svc")
```

### Options inherited from parent commands
Expand Down
28 changes: 28 additions & 0 deletions src/api/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
module github.com/zarf-dev/zarf/src/api

go 1.22.4

replace github.com/zarf-dev/zarf => ../..

require (
github.com/defenseunicorns/pkg/helpers/v2 v2.0.1
github.com/invopop/jsonschema v0.12.0
github.com/stretchr/testify v1.9.0
github.com/zarf-dev/zarf v0.37.0
k8s.io/apimachinery v0.30.3
)

require (
github.com/bahlo/generic-list-go v0.2.0 // indirect
github.com/buger/jsonparser v1.1.1 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/otiai10/copy v1.14.0 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/wk8/go-ordered-map/v2 v2.1.8 // indirect
golang.org/x/sync v0.7.0 // indirect
golang.org/x/sys v0.22.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/utils v0.0.0-20231127182322-b307cd553661 // indirect
oras.land/oras-go/v2 v2.5.0 // indirect
)
37 changes: 37 additions & 0 deletions src/api/go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
github.com/bahlo/generic-list-go v0.2.0 h1:5sz/EEAK+ls5wF+NeqDpk5+iNdMDXrh3z3nPnH1Wvgk=
github.com/bahlo/generic-list-go v0.2.0/go.mod h1:2KvAjgMlE5NNynlg/5iLrrCCZ2+5xWbdbCW3pNTGyYg=
github.com/buger/jsonparser v1.1.1 h1:2PnMjfWD7wBILjqQbt530v576A/cAbQvEW9gGIpYMUs=
github.com/buger/jsonparser v1.1.1/go.mod h1:6RYKKt7H4d4+iWqouImQ9R2FZql3VbhNgx27UK13J/0=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/defenseunicorns/pkg/helpers/v2 v2.0.1 h1:j08rz9vhyD9Bs+yKiyQMY2tSSejXRMxTqEObZ5M1Wbk=
github.com/defenseunicorns/pkg/helpers/v2 v2.0.1/go.mod h1:u1PAqOICZyiGIVA2v28g55bQH1GiAt0Bc4U9/rnWQvQ=
github.com/invopop/jsonschema v0.12.0 h1:6ovsNSuvn9wEQVOyc72aycBMVQFKz7cPdMJn10CvzRI=
github.com/invopop/jsonschema v0.12.0/go.mod h1:ffZ5Km5SWWRAIN6wbDXItl95euhFz2uON45H2qjYt+0=
github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y=
github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0=
github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
github.com/otiai10/copy v1.14.0 h1:dCI/t1iTdYGtkvCuBG2BgR6KZa83PTclw4U5n2wAllU=
github.com/otiai10/copy v1.14.0/go.mod h1:ECfuL02W+/FkTWZWgQqXPWZgW9oeKCSQ5qVfSc4qc4w=
github.com/otiai10/mint v1.5.1 h1:XaPLeE+9vGbuyEHem1JNk3bYc7KKqyI/na0/mLd/Kks=
github.com/otiai10/mint v1.5.1/go.mod h1:MJm72SBthJjz8qhefc4z1PYEieWmy8Bku7CjcAqyUSM=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/wk8/go-ordered-map/v2 v2.1.8 h1:5h/BUHu93oj4gIdvHHHGsScSTMijfx5PeYkE/fJgbpc=
github.com/wk8/go-ordered-map/v2 v2.1.8/go.mod h1:5nJHM5DyteebpVlHnWMV0rPz6Zp7+xBAnxjb1X5vnTw=
golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M=
golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.22.0 h1:RI27ohtqKCnwULzJLqkv897zojh5/DwS/ENaMzUOaWI=
golang.org/x/sys v0.22.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
k8s.io/apimachinery v0.30.3 h1:q1laaWCmrszyQuSQCfNB8cFgCuDAoPszKY4ucAjDwHc=
k8s.io/apimachinery v0.30.3/go.mod h1:iexa2somDaxdnj7bha06bhb43Zpa6eWH8N8dbqVjTUc=
k8s.io/utils v0.0.0-20231127182322-b307cd553661 h1:FepOBzJ0GXm8t0su67ln2wAZjbQ6RxQGZDnzuLcrUTI=
k8s.io/utils v0.0.0-20231127182322-b307cd553661/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0=
oras.land/oras-go/v2 v2.5.0 h1:o8Me9kLY74Vp5uw07QXPiitjsw7qNXi8Twd+19Zf02c=
oras.land/oras-go/v2 v2.5.0/go.mod h1:z4eisnLP530vwIOUOJeBIj0aGI0L1C3d53atvCBqZHg=
6 changes: 3 additions & 3 deletions src/types/component.go → src/api/v1alpha1/component.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: 2021-Present The Zarf Authors

// Package types contains all the types used by Zarf.
package types
// Package v1alpha1 holds the definition of the v1alpha1 Zarf Package
package v1alpha1

import (
"github.com/invopop/jsonschema"
"github.com/zarf-dev/zarf/src/api/v1alpha1/extensions"
"github.com/zarf-dev/zarf/src/pkg/utils/exec"
"github.com/zarf-dev/zarf/src/pkg/variables"
"github.com/zarf-dev/zarf/src/types/extensions"
)

// ZarfComponent is the primary functional grouping of assets to deploy by Zarf.
Expand Down
File renamed without changes.
File renamed without changes.
11 changes: 8 additions & 3 deletions src/types/package.go → src/api/v1alpha1/package.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: 2021-Present The Zarf Authors

// Package types contains all the types used by Zarf.
package types
// Package v1alpha1 holds the definition of the v1alpha1 Zarf Package
package v1alpha1

import "github.com/zarf-dev/zarf/src/pkg/variables"
import (
"github.com/zarf-dev/zarf/src/pkg/variables"
)

// ZarfPackageKind is an enum of the different kinds of Zarf packages.
type ZarfPackageKind string
Expand All @@ -14,10 +16,13 @@ const (
ZarfInitConfig ZarfPackageKind = "ZarfInitConfig"
// ZarfPackageConfig is the default kind of Zarf package, primarily used during `zarf package`.
ZarfPackageConfig ZarfPackageKind = "ZarfPackageConfig"
ApiVersion string = "zarf.dev/v1alpha1"
)

// ZarfPackage the top-level structure of a Zarf config file.
type ZarfPackage struct {
// The API version of the Zarf package.
ApiVersion string `json:"apiVersion,omitempty," jsonschema:"enum=zarf.dev/v1alpha1"`
// The kind of Zarf package.
Kind ZarfPackageKind `json:"kind" jsonschema:"enum=ZarfInitConfig,enum=ZarfPackageConfig,default=ZarfPackageConfig"`
// Package metadata.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: 2021-Present The Zarf Authors

package types
// Package v1alpha1 holds the definition of the v1alpha1 Zarf Package
package v1alpha1

import (
"testing"
Expand Down
19 changes: 13 additions & 6 deletions src/types/validate.go → src/api/v1alpha1/validate.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: 2021-Present The Zarf Authors

// Package types contains all the types used by Zarf.
package types
// Package v1alpha1 holds the definition of the v1alpha1 Zarf Package
package v1alpha1

import (
"errors"
Expand All @@ -16,11 +16,12 @@ import (
"k8s.io/apimachinery/pkg/util/validation"
)

// Zarf looks for these strings in zarf.yaml to make dynamic changes
const (
// ZarfMaxChartNameLength limits helm chart name size to account for K8s/helm limits and zarf prefix
ZarfMaxChartNameLength = 40
errChartReleaseNameEmpty = "release name empty, unable to fallback to chart name"
errChartReleaseNameInvalid = "invalid release name %s: a DNS-1035 label must consist of lower case alphanumeric characters or -, start with an alphabetic character, and end with an alphanumeric character"
ZarfPackageTemplatePrefix = "###ZARF_PKG_TMPL_"
ZarfPackageVariablePrefix = "###ZARF_PKG_VAR_"
ZarfPackageArch = "###ZARF_PKG_ARCH###"
ZarfComponentName = "###ZARF_COMPONENT_NAME###"
)

var (
Expand All @@ -41,6 +42,12 @@ func SupportedOS() []string {
return supportedOS
}

const (
// ZarfMaxChartNameLength limits helm chart name size to account for K8s/helm limits and zarf prefix
ZarfMaxChartNameLength = 40
errChartReleaseNameEmpty = "release name empty, unable to fallback to chart name"
)

// Validate runs all validation checks on the package.
func (pkg ZarfPackage) Validate() error {
var err error
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: 2021-Present The Zarf Authors

// Package types contains all the types used by Zarf.
package types
// Package v1alpha1 holds the definition of the v1alpha1 Zarf Package
package v1alpha1

import (
"fmt"
Expand Down
38 changes: 22 additions & 16 deletions src/cmd/connect.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,9 @@ import (
)

var (
connectResourceName string
connectNamespace string
connectResourceType string
connectLocalPort int
connectRemotePort int
cliOnly bool
cliOnly bool
zt cluster.TunnelInfo
)

var connectCmd = &cobra.Command{
Use: "connect { REGISTRY | GIT | connect-name }",
Aliases: []string{"c"},
Expand All @@ -46,15 +41,24 @@ var connectCmd = &cobra.Command{
ctx := cmd.Context()

var tunnel *cluster.Tunnel
if connectResourceName == "" {
tunnel, err = c.Connect(ctx, target)
} else {
zt := cluster.NewTunnelInfo(connectNamespace, connectResourceType, connectResourceName, "", connectLocalPort, connectRemotePort)
if target == "" {
tunnel, err = c.ConnectTunnelInfo(ctx, zt)
} else {
var ti cluster.TunnelInfo
ti, err = c.NewTargetTunnelInfo(ctx, target)
if err != nil {
return fmt.Errorf("unable to create tunnel: %w", err)
}
if zt.LocalPort != 0 {
ti.LocalPort = zt.LocalPort
}
tunnel, err = c.ConnectTunnelInfo(ctx, ti)
}

if err != nil {
return fmt.Errorf("unable to connect to the service: %w", err)
}

defer tunnel.Close()

// Dump the tunnel URL to the console for other tools to use.
Expand All @@ -64,11 +68,13 @@ var connectCmd = &cobra.Command{
spinner.Updatef(lang.CmdConnectEstablishedCLI, tunnel.FullURL())
} else {
spinner.Updatef(lang.CmdConnectEstablishedWeb, tunnel.FullURL())

if err := exec.LaunchURL(tunnel.FullURL()); err != nil {
message.Debug(err)
}
}

// Wait for the interrupt signal or an error.
select {
case <-ctx.Done():
spinner.Successf(lang.CmdConnectTunnelClosed, tunnel.FullURL())
Expand Down Expand Up @@ -101,10 +107,10 @@ func init() {
rootCmd.AddCommand(connectCmd)
connectCmd.AddCommand(connectListCmd)

connectCmd.Flags().StringVar(&connectResourceName, "name", "", lang.CmdConnectFlagName)
connectCmd.Flags().StringVar(&connectNamespace, "namespace", cluster.ZarfNamespaceName, lang.CmdConnectFlagNamespace)
connectCmd.Flags().StringVar(&connectResourceType, "type", cluster.SvcResource, lang.CmdConnectFlagType)
connectCmd.Flags().IntVar(&connectLocalPort, "local-port", 0, lang.CmdConnectFlagLocalPort)
connectCmd.Flags().IntVar(&connectRemotePort, "remote-port", 0, lang.CmdConnectFlagRemotePort)
connectCmd.Flags().StringVar(&zt.ResourceName, "name", "", lang.CmdConnectFlagName)
connectCmd.Flags().StringVar(&zt.Namespace, "namespace", cluster.ZarfNamespaceName, lang.CmdConnectFlagNamespace)
connectCmd.Flags().StringVar(&zt.ResourceType, "type", cluster.SvcResource, lang.CmdConnectFlagType)
connectCmd.Flags().IntVar(&zt.LocalPort, "local-port", 0, lang.CmdConnectFlagLocalPort)
connectCmd.Flags().IntVar(&zt.RemotePort, "remote-port", 0, lang.CmdConnectFlagRemotePort)
connectCmd.Flags().BoolVar(&cliOnly, "cli-only", false, lang.CmdConnectFlagCliOnly)
}
7 changes: 4 additions & 3 deletions src/cmd/internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"github.com/spf13/cobra"
"github.com/spf13/cobra/doc"
"github.com/spf13/pflag"
"github.com/zarf-dev/zarf/src/api/v1alpha1"
"github.com/zarf-dev/zarf/src/cmd/common"
"github.com/zarf-dev/zarf/src/config/lang"
"github.com/zarf-dev/zarf/src/internal/agent"
Expand Down Expand Up @@ -168,7 +169,7 @@ tableOfContents: false
func addGoComments(reflector *jsonschema.Reflector) error {
addCommentErr := errors.New("this command must be called from the root of the Zarf repo")

typePackagePath := filepath.Join("src", "types")
typePackagePath := filepath.Join("src", "api", "v1alpha1")
if err := reflector.AddGoComments("github.com/zarf-dev/zarf", typePackagePath); err != nil {
return fmt.Errorf("%w: %w", addCommentErr, err)
}
Expand All @@ -189,7 +190,7 @@ var genConfigSchemaCmd = &cobra.Command{
return err
}

schema := reflector.Reflect(&types.ZarfPackage{})
schema := reflector.Reflect(&v1alpha1.ZarfPackage{})
output, err := json.MarshalIndent(schema, "", " ")
if err != nil {
return fmt.Errorf("unable to generate the Zarf config schema: %w", err)
Expand All @@ -201,7 +202,7 @@ var genConfigSchemaCmd = &cobra.Command{

type zarfTypes struct {
DeployedPackage types.DeployedPackage
ZarfPackage types.ZarfPackage
ZarfPackage v1alpha1.ZarfPackage
ZarfState types.ZarfState
}

Expand Down
10 changes: 5 additions & 5 deletions src/config/lang/english.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,11 @@ const (
// zarf connect list
CmdConnectListShort = "Lists all available connection shortcuts"

CmdConnectFlagName = "Specify the resource name. E.g. name=unicorns or name=unicorn-pod-7448499f4d-b5bk6."
CmdConnectFlagNamespace = "Specify the namespace. E.g. namespace=default. Ignored if --name is unset."
CmdConnectFlagType = "Specify the resource type. E.g. type=svc or type=pod. Ignored if --name is unset."
CmdConnectFlagLocalPort = "(Optional, autogenerated if not provided) Specify the local port to bind to. E.g. local-port=42000. Ignored if --name is unset."
CmdConnectFlagRemotePort = "Specify the remote port of the resource to bind to. E.g. remote-port=8080. Ignored if --name is unset."
CmdConnectFlagName = "Specify the resource name. E.g. name=unicorns or name=unicorn-pod-7448499f4d-b5bk6. Ignored if connect-name is supplied."
CmdConnectFlagNamespace = "Specify the namespace. E.g. namespace=default. Ignored if connect-name is supplied."
CmdConnectFlagType = "Specify the resource type. E.g. type=svc or type=pod. Ignored if connect-name is supplied."
CmdConnectFlagLocalPort = "(Optional, autogenerated if not provided) Specify the local port to bind to. E.g. local-port=42000."
CmdConnectFlagRemotePort = "Specify the remote port of the resource to bind to. E.g. remote-port=8080. Ignored if connect-name is supplied."
CmdConnectFlagCliOnly = "Disable browser auto-open"

CmdConnectPreparingTunnel = "Preparing a tunnel to connect to %s"
Expand Down
Loading

0 comments on commit f0981a0

Please sign in to comment.