Skip to content

Commit

Permalink
update postgres example with zarf connect & secret injection
Browse files Browse the repository at this point in the history
  • Loading branch information
jeff-mccoy committed Feb 8, 2022
1 parent eca4cff commit 3795af3
Show file tree
Hide file tree
Showing 13 changed files with 100 additions and 76 deletions.
19 changes: 11 additions & 8 deletions cli/cmd/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,19 @@ var packageCmd = &cobra.Command{
}

var packageCreateCmd = &cobra.Command{
Use: "create",
Short: "Create an update package to push to the gitops server (runs online)",
Use: "create",
Aliases: []string{"c"},
Short: "Create an update package to push to the gitops server (runs online)",
Run: func(cmd *cobra.Command, args []string) {
packager.Create()
},
}

var packageDeployCmd = &cobra.Command{
Use: "deploy [PACKAGE]",
Short: "Deploys an update package from a local file or URL (runs offline)",
Args: cobra.MaximumNArgs(1),
Use: "deploy [PACKAGE]",
Aliases: []string{"d"},
Short: "Deploys an update package from a local file or URL (runs offline)",
Args: cobra.MaximumNArgs(1),
Run: func(cmd *cobra.Command, args []string) {
var done func()
packageName := choosePackage(args)
Expand All @@ -40,9 +42,10 @@ var packageDeployCmd = &cobra.Command{
}

var packageInspectCmd = &cobra.Command{
Use: "inspect [PACKAGE]",
Short: "lists the payload of an update package file (runs offline)",
Args: cobra.MaximumNArgs(1),
Use: "inspect [PACKAGE]",
Aliases: []string{"i"},
Short: "lists the payload of an update package file (runs offline)",
Args: cobra.MaximumNArgs(1),
Run: func(cmd *cobra.Command, args []string) {
packageName := choosePackage(args)
packager.Inspect(packageName)
Expand Down
34 changes: 20 additions & 14 deletions cli/cmd/tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,16 @@ var toolsCmd = &cobra.Command{

// destroyCmd represents the init command
var archiverCmd = &cobra.Command{
Use: "archiver",
Short: "Compress/Decompress tools",
Use: "archiver",
Aliases: []string{"a"},
Short: "Compress/Decompress tools",
}

var archiverCompressCmd = &cobra.Command{
Use: "compress SOURCES ARCHIVE",
Short: "Compress a collection of sources based off of the destination file extension",
Args: cobra.MinimumNArgs(2),
Use: "compress SOURCES ARCHIVE",
Aliases: []string{"c"},
Short: "Compress a collection of sources based off of the destination file extension",
Args: cobra.MinimumNArgs(2),
Run: func(cmd *cobra.Command, args []string) {
sourceFiles, destinationArchive := args[:len(args)-1], args[len(args)-1]
err := archiver.Archive(sourceFiles, destinationArchive)
Expand All @@ -43,9 +45,10 @@ var archiverCompressCmd = &cobra.Command{
}

var archiverDecompressCmd = &cobra.Command{
Use: "decompress ARCHIVE DESTINATION",
Short: "Decompress an archive to a specified location.",
Args: cobra.ExactArgs(2),
Use: "decompress ARCHIVE DESTINATION",
Aliases: []string{"d"},
Short: "Decompress an archive to a specified location.",
Args: cobra.ExactArgs(2),
Run: func(cmd *cobra.Command, args []string) {
sourceArchive, destinationPath := args[0], args[1]
err := archiver.Unarchive(sourceArchive, destinationPath)
Expand All @@ -56,8 +59,9 @@ var archiverDecompressCmd = &cobra.Command{
}

var registryCmd = &cobra.Command{
Use: "registry",
Short: "Collection of registry commands provided by Crane",
Use: "registry",
Aliases: []string{"r"},
Short: "Collection of registry commands provided by Crane",
}

var readCredsCmd = &cobra.Command{
Expand All @@ -70,8 +74,9 @@ var readCredsCmd = &cobra.Command{
}

var configSchemaCmd = &cobra.Command{
Use: "config-schema",
Short: "Generates a JSON schema for the zarf.yaml configuration",
Use: "config-schema",
Aliases: []string{"c"},
Short: "Generates a JSON schema for the zarf.yaml configuration",
Run: func(cmd *cobra.Command, args []string) {
schema := jsonschema.Reflect(&types.ZarfPackage{})
output, err := json.MarshalIndent(schema, "", " ")
Expand All @@ -83,8 +88,9 @@ var configSchemaCmd = &cobra.Command{
}

var k9sCmd = &cobra.Command{
Use: "k9s",
Short: "Launch K9s tool for managing K8s clusters",
Use: "monitor",
Aliases: []string{"m", "k9s"},
Short: "Launch K9s tool for managing K8s clusters",
Run: func(cmd *cobra.Command, args []string) {
// Hack to make k9s think it's all alone
os.Args = []string{os.Args[0], "-n", "zarf"}
Expand Down
8 changes: 6 additions & 2 deletions cli/internal/helm/chart.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func InstallOrUpgradeChart(options ChartOptions) ConnectStrings {
var output *release.Release

options.ReleaseName = fmt.Sprintf("zarf-%s", options.Chart.Name)
actionConfig, err := createActionConfig(options.Chart.Namespace)
actionConfig, err := createActionConfig(options.Chart.Namespace, spinner)
postRender := NewRenderer(options, actionConfig)

// Setup K8s connection
Expand Down Expand Up @@ -114,8 +114,10 @@ func InstallOrUpgradeChart(options ChartOptions) ConnectStrings {
// TemplateChart generates a helm template from a given chart
func TemplateChart(options ChartOptions) (string, error) {
message.Debugf("helm.TemplateChart(%v)", options)
spinner := message.NewProgressSpinner("Templating helm chart %s", options.Chart.Name)
defer spinner.Stop()

actionConfig, err := createActionConfig(options.Chart.Namespace)
actionConfig, err := createActionConfig(options.Chart.Namespace, spinner)

// Setup K8s connection
if err != nil {
Expand Down Expand Up @@ -146,6 +148,8 @@ func TemplateChart(options ChartOptions) (string, error) {
return "", fmt.Errorf("error generating helm chart template: %w", err)
}

spinner.Success()

return templatedChart.Manifest, nil
}

Expand Down
4 changes: 2 additions & 2 deletions cli/internal/helm/destroy.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ func Destroy(purgeAllZarfInstallations bool) {
defer spinner.Stop()

// Initially load the actionConfig without a namespace
actionConfig, err := createActionConfig("")
actionConfig, err := createActionConfig("", spinner)
if err != nil {
// Don't fatal since this is a removal action
spinner.Errorf(err, "Unable to initialize the K8s client")
Expand Down Expand Up @@ -45,7 +45,7 @@ func Destroy(purgeAllZarfInstallations bool) {
if zarfPrefix.MatchString(release.Name) {
spinner.Updatef("Uninstalling helm chart %s/%s", release.Namespace, release.Name)
// Establish a new actionConfig for the namespace
actionConfig, _ = createActionConfig(release.Namespace)
actionConfig, _ = createActionConfig(release.Namespace, spinner)
// Perform the uninstall
response, err := uninstallChart(actionConfig, release.Name)
message.Debug(response)
Expand Down
1 change: 1 addition & 0 deletions cli/internal/helm/post-render.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ func (r *renderer) Run(renderedManifests *bytes.Buffer) (*bytes.Buffer, error) {
if r.options.Component.SecretName != "" {
// A custom secret name was given for this component
secretName = r.options.Component.SecretName
message.Debugf("using custom zarf secret name %s", secretName)
}

// Write the context to a file for processing
Expand Down
4 changes: 2 additions & 2 deletions cli/internal/helm/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func parseChartValues(options ChartOptions) (map[string]interface{}, error) {
return valueOpts.MergeValues(providers)
}

func createActionConfig(namespace string) (*action.Configuration, error) {
func createActionConfig(namespace string, spinner *message.Spinner) (*action.Configuration, error) {
// OMG THIS IS SOOOO GROSS PPL... https://github.com/helm/helm/issues/8780
_ = os.Setenv("HELM_NAMESPACE", namespace)

Expand All @@ -73,7 +73,7 @@ func createActionConfig(namespace string) (*action.Configuration, error) {
settings := cli.New()

// Setup K8s connection
err := actionConfig.Init(settings.RESTClientGetter(), namespace, "", message.Debugf)
err := actionConfig.Init(settings.RESTClientGetter(), namespace, "", spinner.Updatef)

return actionConfig, err
}
14 changes: 0 additions & 14 deletions examples/postgres-operator/manifests/minio-instance-ingress.yaml

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
apiVersion: v1
kind: Service
metadata:
name: minio-console-zarf-connect
namespace: minio-operator
annotations:
zarf.dev/connect-description: "Launch the minio console"
labels:
zarf.dev/connect-name: minio
spec:
selector:
v1.min.io/tenant: zarf-minio-instance
ports:
- name: http-console
port: 9090
protocol: TCP
targetPort: 9090
14 changes: 0 additions & 14 deletions examples/postgres-operator/manifests/pgadmin-ingress.yaml

This file was deleted.

18 changes: 18 additions & 0 deletions examples/postgres-operator/manifests/pgadmin-zarf-connect.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
apiVersion: v1
kind: Service
metadata:
name: pgadmin-zarf-connect
namespace: postgres-operator
annotations:
zarf.dev/connect-description: "Launch the pgadmin web interface"
labels:
zarf.dev/connect-name: pgadmin
spec:
selector:
app.kubernetes.io/instance: zarf-pgadmin4
app.kubernetes.io/name: pgadmin4
ports:
- name: http
port: 80
protocol: TCP
targetPort: 80

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
apiVersion: v1
kind: Service
metadata:
name: postgres-operator-ui-zarf-connect
namespace: postgres-operator
annotations:
zarf.dev/connect-description: "Launch the postgres opertor web interface"
labels:
zarf.dev/connect-name: postgres-operator-ui
spec:
selector:
app.kubernetes.io/instance: zarf-postgres-operator-ui
app.kubernetes.io/name: postgres-operator-ui
ports:
- name: http
port: 80
protocol: TCP
targetPort: 8081
11 changes: 5 additions & 6 deletions examples/postgres-operator/zarf.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,17 @@ components:
- name: baseline
required: true
# Big Bang charts expect this
secretName: "private-registry"
secretName: "private-registry"

manifests:
- name: postgres-example-config
# @todo: update IngressRoute manifets to use k8s Ingress or Zarf Connect logic
files:
- manifests/patch-svc-accounts.yaml
# - manifests/minio-instance-ingress.yaml
- manifests/pgadmin-ingress.yaml
# - manifests/postgres-cluster.yaml
- manifests/minio-instance-zarf-connect.yaml
- manifests/pgadmin-zarf-connect.yaml
- manifests/postgres-cluster.yaml
- manifests/postgres-operator.yaml
# - manifests/postgres-operator-ui-ingress.yaml
- manifests/postgres-operator-ui-zarf-connect.yaml
charts:
- name: postgres-operator
url: https://opensource.zalando.com/postgres-operator/charts/postgres-operator
Expand Down

0 comments on commit 3795af3

Please sign in to comment.