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

feat: Added example to admin-cluster.go and projectwindow.go files new PR #16103

Closed
wants to merge 5 commits 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
10 changes: 0 additions & 10 deletions cmd/argocd/commands/admin/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,6 @@ func NewAppCommand(clientOpts *argocdclient.ClientOptions) *cobra.Command {
var command = &cobra.Command{
Use: "app",
Short: "Manage applications configuration",
Example: `
# Compare results of two reconciliations and print diff
argocd admin app diff-reconcile-results APPNAME [flags]

# Generate declarative config for an application
argocd admin app generate-spec APPNAME

# Reconcile all applications and store reconciliation summary in the specified file
argocd admin app get-reconcile-results APPNAME
`,
Run: func(c *cobra.Command, args []string) {
c.HelpFunc()(c, args)
},
Expand Down
36 changes: 36 additions & 0 deletions cmd/argocd/commands/admin/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,15 @@ func NewClusterCommand(clientOpts *argocdclient.ClientOptions, pathOpts *clientc
var command = &cobra.Command{
Use: "cluster",
Short: "Manage clusters configuration",
Example: `
# Authenticate with a Token
argocd admin cluster --auth-token YOUR_AUTH_TOKEN

# Use a Custom Client Certificate and Key
argocd admin cluster --client-crt /path/to/client.crt --client-crt-key /path/to/client.key

# Set Logging Format and Level
argocd admin cluster --logformat json --loglevel debug`,
Run: func(c *cobra.Command, args []string) {
c.HelpFunc()(c, args)
},
Expand Down Expand Up @@ -448,6 +457,21 @@ func NewClusterStatsCommand(clientOpts *argocdclient.ClientOptions) *cobra.Comma
var command = cobra.Command{
Use: "stats",
Short: "Prints information cluster statistics and inferred shard number",
Example: `
#Display Cluster Statistics for the Default Cluster
argocd admin cluster stats

#Display Cluster Statistics for a Specific Cluster Context
argocd admin cluster stats --context=my-cluster-context

#Display Cluster Statistics for a Cluster with Custom Configuration (Kubeconfig Path)
argocd admin cluster stats --kubeconfig=/path/to/custom/kubeconfig.yaml

#Display Cluster Statistics with a Custom Request Timeout
argocd admin cluster stats --request-timeout=5s

#Display Cluster Statistics for a Specific Shard
argocd admin cluster stats --shard=1`,
Run: func(cmd *cobra.Command, args []string) {
ctx := cmd.Context()

Expand Down Expand Up @@ -492,6 +516,18 @@ func NewClusterConfig() *cobra.Command {
Use: "kubeconfig CLUSTER_URL OUTPUT_PATH",
Short: "Generates kubeconfig for the specified cluster",
DisableAutoGenTag: true,
Example: `
#Generate a Kubeconfig for a Cluster and Save it to a File
argocd admin cluster kubeconfig https://cluster-api-url:6443 /path/to/output/kubeconfig.yaml

#Generate a Kubeconfig with a Custom Cluster Name:
argocd admin cluster kubeconfig https://cluster-api-url:6443 /path/to/output/kubeconfig.yaml --cluster=my-cluster

#Generate a Kubeconfig for a Cluster with TLS Verification Disabled
argocd admin cluster kubeconfig https://cluster-api-url:6443 /path/to/output/kubeconfig.yaml --insecure-skip-tls-verify

#Generate a Kubeconfig with a Custom Namespace Scope
argocd admin cluster kubeconfig https://cluster-api-url:6443 /path/to/output/kubeconfig.yaml -n my-namespace`,
Run: func(c *cobra.Command, args []string) {
ctx := c.Context()

Expand Down
12 changes: 2 additions & 10 deletions cmd/argocd/commands/app_resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package commands
import (
"fmt"
"os"
"text/tabwriter"

"github.com/argoproj/argo-cd/v2/cmd/util"
"github.com/argoproj/argo-cd/v2/pkg/apis/application/v1alpha1"
Expand All @@ -19,6 +18,8 @@ import (
"github.com/argoproj/argo-cd/v2/util/argo"
"github.com/argoproj/argo-cd/v2/util/errors"
argoio "github.com/argoproj/argo-cd/v2/util/io"

"text/tabwriter"
)

func NewApplicationPatchResourceCommand(clientOpts *argocdclient.ClientOptions) *cobra.Command {
Expand All @@ -29,7 +30,6 @@ func NewApplicationPatchResourceCommand(clientOpts *argocdclient.ClientOptions)
var kind string
var group string
var all bool
var project string
command := &cobra.Command{
Use: "patch-resource APPNAME",
Short: "Patch resource in an application",
Expand All @@ -46,7 +46,6 @@ func NewApplicationPatchResourceCommand(clientOpts *argocdclient.ClientOptions)
command.Flags().StringVar(&group, "group", "", "Group")
command.Flags().StringVar(&namespace, "namespace", "", "Namespace")
command.Flags().BoolVar(&all, "all", false, "Indicates whether to patch multiple matching of resources")
command.Flags().StringVar(&project, "project", "", `The name of the application's project - specifying this allows the command to report "not found" instead of "permission denied" if the app does not exist`)
command.Run = func(c *cobra.Command, args []string) {
ctx := c.Context()

Expand Down Expand Up @@ -78,7 +77,6 @@ func NewApplicationPatchResourceCommand(clientOpts *argocdclient.ClientOptions)
Kind: pointer.String(gvk.Kind),
Patch: pointer.String(patch),
PatchType: pointer.String(patchType),
Project: pointer.String(project),
})
errors.CheckError(err)
log.Infof("Resource '%s' patched", obj.GetName())
Expand All @@ -96,7 +94,6 @@ func NewApplicationDeleteResourceCommand(clientOpts *argocdclient.ClientOptions)
var force bool
var orphan bool
var all bool
var project string
command := &cobra.Command{
Use: "delete-resource APPNAME",
Short: "Delete resource in an application",
Expand All @@ -111,7 +108,6 @@ func NewApplicationDeleteResourceCommand(clientOpts *argocdclient.ClientOptions)
command.Flags().BoolVar(&force, "force", false, "Indicates whether to orphan the dependents of the deleted resource")
command.Flags().BoolVar(&orphan, "orphan", false, "Indicates whether to force delete the resource")
command.Flags().BoolVar(&all, "all", false, "Indicates whether to patch multiple matching of resources")
command.Flags().StringVar(&project, "project", "", `The name of the application's project - specifying this allows the command to report "not found" instead of "permission denied" if the app does not exist`)
command.Run = func(c *cobra.Command, args []string) {
ctx := c.Context()

Expand Down Expand Up @@ -143,7 +139,6 @@ func NewApplicationDeleteResourceCommand(clientOpts *argocdclient.ClientOptions)
Kind: pointer.String(gvk.Kind),
Force: &force,
Orphan: &orphan,
Project: pointer.String(project),
})
errors.CheckError(err)
log.Infof("Resource '%s' deleted", obj.GetName())
Expand Down Expand Up @@ -255,7 +250,6 @@ func printResources(listAll bool, orphaned bool, appResourceTree *v1alpha1.Appli
func NewApplicationListResourcesCommand(clientOpts *argocdclient.ClientOptions) *cobra.Command {
var orphaned bool
var output string
var project string
var command = &cobra.Command{
Use: "resources APPNAME",
Short: "List resource of application",
Expand All @@ -272,14 +266,12 @@ func NewApplicationListResourcesCommand(clientOpts *argocdclient.ClientOptions)
appResourceTree, err := appIf.ResourceTree(ctx, &applicationpkg.ResourcesQuery{
ApplicationName: &appName,
AppNamespace: &appNs,
Project: &project,
})
errors.CheckError(err)
printResources(listAll, orphaned, appResourceTree, output)
},
}
command.Flags().BoolVar(&orphaned, "orphaned", false, "Lists only orphaned resources")
command.Flags().StringVar(&output, "output", "", "Provides the tree view of the resources")
command.Flags().StringVar(&project, "project", "", `The name of the application's project - specifying this allows the command to report "not found" instead of "permission denied" if the app does not exist`)
return command
}
80 changes: 73 additions & 7 deletions cmd/argocd/commands/projectwindows.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,22 @@ func NewProjectWindowsCommand(clientOpts *argocdclient.ClientOptions) *cobra.Com
roleCommand := &cobra.Command{
Use: "windows",
Short: "Manage a project's sync windows",
Example: `#Creating "MyApp" Project in Argo CD with Custom Configuration and gRPC-Web Authentication
argocd proj windows --auth-token "your-auth-token" \
--client-crt "/path/to/client.crt" \
--client-crt-key "/path/to/client.key" \
--config "/path/to/custom/config.yaml" \
--grpc-web \
--grpc-web-root-path "/custom/root/path" \
--server "argocd-server.example.com" \
"MyApp"

#Configuring "Development" Project in Argo CD with HTTP, Custom kube-context, and Debug Logging.
argocd proj windows --plaintext \
--kube-context "my-kube-context" \
--loglevel "debug" \
--server "argocd-server.internal.local" \
"Development"`,
Run: func(c *cobra.Command, args []string) {
c.HelpFunc()(c, args)
os.Exit(1)
Expand All @@ -42,6 +58,21 @@ func NewProjectWindowsDisableManualSyncCommand(clientOpts *argocdclient.ClientOp
Use: "disable-manual-sync PROJECT ID",
Short: "Disable manual sync for a sync window",
Long: "Disable manual sync for a sync window. Requires ID which can be found by running \"argocd proj windows list PROJECT\"",
Example: `#Disabling Manual Synchronization for Project "my-project-id" in Argo CD with Custom Configuration
argocd proj windows disable-manual-sync my-project-id \
--auth-token "your-auth-token" \
--kube-context "my-kube-context" \
--loglevel "debug" \
--server "argocd-server.example.com"


#Disabling Manual Synchronization for Project "another-project-id" in Argo CD with Client Certificates and gRPC-Web Configuration
aargocd proj windows disable-manual-sync another-project-id \
--client-crt "/path/to/client.crt" \
--client-crt-key "/path/to/client.key" \
--grpc-web \
--grpc-web-root-path "/custom/root/path" \
--server "argocd-server.internal.local"`,
Run: func(c *cobra.Command, args []string) {
ctx := c.Context()

Expand Down Expand Up @@ -79,6 +110,20 @@ func NewProjectWindowsEnableManualSyncCommand(clientOpts *argocdclient.ClientOpt
Use: "enable-manual-sync PROJECT ID",
Short: "Enable manual sync for a sync window",
Long: "Enable manual sync for a sync window. Requires ID which can be found by running \"argocd proj windows list PROJECT\"",
Example: `#Enabling Manual Synchronization for Project 'my-project-id' in Argo CD with Custom Configuration:
argocd proj windows enable-manual-sync my-project-id \
--auth-token "your-auth-token" \
--kube-context "my-kube-context" \
--grpc-web \
--loglevel "debug"


#Enabling Manual Synchronization for Project 'another-project-id' in Argo CD with Client Certificates and Port Forwarding
argocd proj windows enable-manual-sync another-project-id \
--client-crt "/path/to/client.crt" \
--client-crt-key "/path/to/client.key" \
--port-forward \
--port-forward-namespace "my-namespace"`,
Run: func(c *cobra.Command, args []string) {
ctx := c.Context()

Expand Down Expand Up @@ -180,6 +225,18 @@ func NewProjectWindowsDeleteCommand(clientOpts *argocdclient.ClientOptions) *cob
var command = &cobra.Command{
Use: "delete PROJECT ID",
Short: "Delete a sync window from a project. Requires ID which can be found by running \"argocd proj windows list PROJECT\"",
Example: `#Deleting Project 'my-project-id' in Argo CD with Custom Configuration
argocd proj windows delete my-project-id \
--auth-token "your-auth-token" \
--kube-context "my-kube-context" \
--loglevel "debug"

#Deleting Project 'another-project-id' in Argo CD with Client Certificates and TLS Verification Skip
argocd proj windows delete another-project-id \
--client-crt "/path/to/client.crt" \
--client-crt-key "/path/to/client.key" \
--insecure \
--server-crt "/path/to/server.crt"`,
Run: func(c *cobra.Command, args []string) {
ctx := c.Context()

Expand Down Expand Up @@ -274,12 +331,22 @@ func NewProjectWindowsListCommand(clientOpts *argocdclient.ClientOptions) *cobra
var command = &cobra.Command{
Use: "list PROJECT",
Short: "List project sync windows",
Example: `# List project windows
Example: `#Listing Windows for Project 'my-project-id' in Argo CD with Custom Configuration
argocd proj windows list my-project-id \
--auth-token "your-auth-token" \
--kube-context "my-kube-context" \
--loglevel "debug"
#Listing Windows for Project 'another-project-id' in Argo CD with Client Certificates and TLS Verification Skip
argocd proj windows list another-project-id \
--client-crt "/path/to/client.crt" \
--client-crt-key "/path/to/client.key" \
--insecure \
--server-crt "/path/to/server.crt"
#List project windows
argocd proj windows list PROJECT

# List project windows in yaml format
argocd proj windows list PROJECT -o yaml
`,
argocd proj windows list PROJECT -o yaml`,
Run: func(c *cobra.Command, args []string) {
ctx := c.Context()

Expand Down Expand Up @@ -312,8 +379,8 @@ argocd proj windows list PROJECT -o yaml
func printSyncWindows(proj *v1alpha1.AppProject) {
w := tabwriter.NewWriter(os.Stdout, 0, 0, 2, ' ', 0)
var fmtStr string
headers := []interface{}{"ID", "STATUS", "KIND", "SCHEDULE", "DURATION", "APPLICATIONS", "NAMESPACES", "CLUSTERS", "MANUALSYNC", "TIMEZONE"}
fmtStr = strings.Repeat("%s\t", len(headers)) + "\n"
headers := []interface{}{"ID", "STATUS", "KIND", "SCHEDULE", "DURATION", "APPLICATIONS", "NAMESPACES", "CLUSTERS", "MANUALSYNC"}
fmtStr = "%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n"
fmt.Fprintf(w, fmtStr, headers...)
if proj.Spec.SyncWindows.HasWindows() {
for i, window := range proj.Spec.SyncWindows {
Expand All @@ -327,7 +394,6 @@ func printSyncWindows(proj *v1alpha1.AppProject) {
formatListOutput(window.Namespaces),
formatListOutput(window.Clusters),
formatManualOutput(window.ManualSync),
window.TimeZone,
}
fmt.Fprintf(w, fmtStr, vals...)
}
Expand Down
34 changes: 0 additions & 34 deletions docs/operator-manual/notifications/templates.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ Each template has access to the following fields:

- `app` holds the application object.
- `context` is a user-defined string map and might include any string keys and values.
- `secrets` provides access to sensitive data stored in `argocd-notifications-secret`
- `serviceType` holds the notification service type name (such as "slack" or "email). The field can be used to conditionally
render service-specific fields.
- `recipient` holds the recipient name.
Expand All @@ -44,39 +43,6 @@ data:
message: "Something happened in {{ .context.environmentName }} in the {{ .context.region }} data center!"
```

## Defining and using secrets within notification templates

Some notification service use cases will require the use of secrets within templates. This can be achieved with the use of
the `secrets` data variable available within the templates.

Given that we have the following `argocd-notifications-secret`:

```yaml
apiVersion: v1
kind: Secret
metadata:
name: argocd-notifications-secret
stringData:
sampleWebhookToken: secret-token
type: Opaque
```

We can use the defined `sampleWebhookToken` in a template as such:

```yaml
apiVersion: v1
kind: ConfigMap
metadata:
name: argocd-notifications-cm
data:
template.trigger-webhook: |
webhook:
sample-webhook:
method: POST
path: 'webhook/endpoint/with/auth'
body: 'token={{ .secrets.sampleWebhookToken }}&variables[APP_SOURCE_PATH]={{ .app.spec.source.path }}
```

## Notification Service Specific Fields

The `message` field of the template definition allows creating a basic notification for any notification service. You can leverage notification service-specific
Expand Down
Loading
Loading