Skip to content

Commit

Permalink
update: example-ascp with --json-format and --k8s-secret (#221)
Browse files Browse the repository at this point in the history
  • Loading branch information
aaroniscode authored Aug 19, 2024
1 parent 0757dd2 commit 74fc767
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 9 deletions.
11 changes: 5 additions & 6 deletions pkg/application/example/ascp/ascp.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import (
//

func NewApp() *application.Application {
options, flags := newOptions()

return &application.Application{
Command: cmd.Command{
Parent: "example",
Expand All @@ -31,19 +33,16 @@ func NewApp() *application.Application {
}),
},

Flags: flags,

Installer: &installer.ManifestInstaller{
AppName: "example-ascp",
ResourceTemplate: &template.TextTemplate{
Template: secretsProviderClassTemplate + serviceAccountTemplate + serviceAndDeploymentTemplate,
},
},

Options: &application.ApplicationOptions{
DisableServiceAccountFlag: true,
DisableVersionFlag: true,
Namespace: "ascp",
ServiceAccount: "nginx-deployment-sa",
},
Options: options,
}
}

Expand Down
28 changes: 25 additions & 3 deletions pkg/application/example/ascp/manifest.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package ascp

// https://github.com/aws/secrets-store-csi-driver-provider-aws/blob/main/examples/ExampleDeployment.yaml
// https://github.com/aws/secrets-store-csi-driver-provider-aws/blob/main/examples/ExampleSecretProviderClass.yaml
const secretsProviderClassTemplate = `---
apiVersion: secrets-store.csi.x-k8s.io/v1
kind: SecretProviderClass
Expand All @@ -10,8 +10,30 @@ spec:
provider: aws
parameters:
objects: |
- objectName: "MySecret"
objectType: "secretsmanager"
- objectName: "MySecret"
objectType: "secretsmanager"
{{- if .JSONFormat }}
jmesPath:
- path: "username"
objectAlias: "dbuser"
- path: "password"
objectAlias: "dbpass"
{{- end }}
{{- if .K8sSecret }}
secretObjects:
- data:
{{- if .JSONFormat }}
- key: dbuser
objectName: dbuser
- key: dbpass
objectName: dbpass
{{- else }}
- key: mysecret
objectName: MySecret
{{- end}}
secretName: nginx-deployment-aws-secrets
type: Opaque
{{- end }}
`

const serviceAccountTemplate = `---
Expand Down
42 changes: 42 additions & 0 deletions pkg/application/example/ascp/options.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package ascp

import (
"github.com/awslabs/eksdemo/pkg/application"
"github.com/awslabs/eksdemo/pkg/cmd"
)

type Options struct {
application.ApplicationOptions
JSONFormat bool
K8sSecret bool
}

func newOptions() (options *Options, flags cmd.Flags) {
options = &Options{
ApplicationOptions: application.ApplicationOptions{
DisableServiceAccountFlag: true,
DisableVersionFlag: true,
Namespace: "ascp",
ServiceAccount: "nginx-deployment-sa",
},
}

flags = cmd.Flags{
&cmd.BoolFlag{
CommandFlag: cmd.CommandFlag{
Name: "json-format",
Description: "mount key/value pairs from a secret in json format",
},
Option: &options.JSONFormat,
},
&cmd.BoolFlag{
CommandFlag: cmd.CommandFlag{
Name: "k8s-secret",
Description: "create a Kubernetes Secret to mirror the mounted secret",
},
Option: &options.K8sSecret,
},
}

return
}

0 comments on commit 74fc767

Please sign in to comment.