{"record":{"id":"a746ca2858c2ad27","repo":"kubernetes/kops","slug":"name-is-required-a746ca","errorCode":null,"errorMessage":"--name is required","messagePattern":"--name is required","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/kops/get_secrets.go","lineNumber":65,"sourceCode":"\tType        string\n\tSecretNames []string\n}\n\nfunc NewCmdGetSecrets(f *util.Factory, out io.Writer, getOptions *GetOptions) *cobra.Command {\n\toptions := GetSecretsOptions{\n\t\tGetOptions: getOptions,\n\t}\n\tcmd := &cobra.Command{\n\t\tUse:     \"secrets [SECRET_NAME]...\",\n\t\tAliases: []string{\"secret\"},\n\t\tShort:   getSecretShort,\n\t\tExample: getSecretExample,\n\t\tArgs: func(cmd *cobra.Command, args []string) error {\n\t\t\toptions.SecretNames = args\n\t\t\toptions.ClusterName = rootCommand.ClusterName(true)\n\n\t\t\tif options.ClusterName == \"\" {\n\t\t\t\treturn fmt.Errorf(\"--name is required\")\n\t\t\t}\n\n\t\t\treturn nil\n\t\t},\n\t\tValidArgsFunction: completeSecretNames(f),\n\t\tRunE: func(cmd *cobra.Command, args []string) error {\n\t\t\treturn RunGetSecrets(cmd.Context(), f, out, &options)\n\t\t},\n\t}\n\n\tcmd.Flags().StringVarP(&options.Type, \"type\", \"\", \"\", \"Filter by secret type\")\n\tcmd.Flags().MarkHidden(\"type\")\n\treturn cmd\n}\n\nfunc listSecrets(secretStore fi.SecretStore, names []string) ([]string, error) {\n\titems, err := secretStore.ListSecrets()\n\tif err != nil {","sourceCodeStart":47,"sourceCodeEnd":83,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/cmd/kops/get_secrets.go#L47-L83","documentation":"The `kops get secrets` command validates that a cluster name is available before running. kOps stores secrets per-cluster, so without a cluster name it cannot know which secret store to query. The name comes from the --name flag, the --name flag on the command, or the KOPS_CLUSTER_NAME environment variable; if none is set, Args returns this error before RunE executes.","triggerScenarios":"Running `kops get secrets` with no --name flag, no KOPS_CLUSTER_NAME env var, and no cluster configured in the current kops state; also running from a directory where kops cannot infer the cluster from a kubectl context.","commonSituations":"Scripting kops in CI without KOPS_CLUSTER_NAME set; running against a fresh state store with no default cluster; users who normally rely on kubectl context inference but run from an unrelated directory.","solutions":["Pass --name <clustername> to the kops get secrets command","Export KOPS_CLUSTER_NAME=<clustername> in the environment or CI pipeline","cd into a directory whose kubectl context maps to the target cluster so kops can infer the name","Run `kops get clusters` first to list valid cluster names"],"exampleFix":"// before\nkops get secrets\n\n// after\nkops get secrets --name mycluster.example.com","handlingStrategy":"validation","validationCode":"clusterName := rootCommand.ClusterName(true)\nif clusterName == \"\" {\n\treturn fmt.Errorf(\"--name is required\")\n}\n// or in shell:\n// [ -n \"$KOPS_CLUSTER_NAME\" ] || KOPS_CLUSTER_NAME=mycluster.example.com","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always pass --name explicitly in scripts","Set KOPS_CLUSTER_NAME in CI environments","Run `kops get clusters` first to validate the cluster name"],"tags":["cli","kops","cluster-name","missing-flag"],"backgroundTag":"missing-required-flag","analyzedSha":"4c8573c808a73d578c5eadc86d410646ea0b0d73","analyzedAt":"2026-09-05T04:13:19.212Z","contentChangedAt":"2026-09-05T04:13:19.212Z","schemaVersion":2},"datasetVersion":"2026-09-12T12:17:11.808Z"}