{"record":{"id":"030d86a9d2edb948","repo":"kubernetes/kops","slug":"error-reading-kubeconfig-w","errorCode":null,"errorMessage":"error reading kubeconfig: %w","messagePattern":"error reading kubeconfig: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/kops/update_cluster.go","lineNumber":539,"sourceCode":"func findBastionPublicName(c *kops.Cluster) string {\n\ttopology := c.Spec.Networking.Topology\n\tif topology == nil {\n\t\treturn \"\"\n\t}\n\tbastion := topology.Bastion\n\tif bastion == nil {\n\t\treturn \"\"\n\t}\n\treturn bastion.PublicName\n}\n\n// clusterIsInKubeConfig checks if we have a context with the specified name (cluster name) in ~/.kube/config.\n// It is used as a check to see if this is (likely) a new cluster.\nfunc clusterIsInKubeConfig(contextName string) (bool, error) {\n\tconfigAccess := clientcmd.NewDefaultPathOptions()\n\tconfig, err := configAccess.GetStartingConfig()\n\tif err != nil {\n\t\treturn false, fmt.Errorf(\"error reading kubeconfig: %w\", err)\n\t}\n\n\tfor k := range config.Contexts {\n\t\tif k == contextName {\n\t\t\treturn true, nil\n\t\t}\n\t}\n\n\treturn false, nil\n}\n\nfunc completeUpdateClusterTarget(f commandutils.Factory, options *CoreUpdateClusterOptions) func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {\n\treturn func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {\n\t\tctx := cmd.Context()\n\n\t\tcommandutils.ConfigureKlogForCompletion()\n\n\t\tcluster, _, _, directive := GetClusterForCompletion(ctx, f, nil)","sourceCodeStart":521,"sourceCodeEnd":557,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/cmd/kops/update_cluster.go#L521-L557","documentation":"Wraps a failure of clientcmd GetStartingConfig while clusterIsInKubeConfig reads ~/.kube/config to guess whether the cluster is new. The kubeconfig file could not be loaded/parsed, so the 'is this cluster known locally' check cannot run.","triggerScenarios":"Thrown at cmd/kops/update_cluster.go:539 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Check that ~/.kube/config exists and is valid YAML","Set KUBECONFIG explicitly to a readable file","Regenerate the kubeconfig with kops export kubecfg"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"4c8573c808a73d578c5eadc86d410646ea0b0d73","analyzedAt":"2026-09-05T04:13:19.212Z","contentChangedAt":"2026-09-05T04:13:19.212Z","schemaVersion":2},"datasetVersion":"2026-09-12T07:17:12.445Z"}