kubernetes/kops · error

error reading kubeconfig: %w

Error message

error reading kubeconfig: %w

What it means

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.

Source

Thrown at cmd/kops/update_cluster.go:539

func findBastionPublicName(c *kops.Cluster) string {
	topology := c.Spec.Networking.Topology
	if topology == nil {
		return ""
	}
	bastion := topology.Bastion
	if bastion == nil {
		return ""
	}
	return bastion.PublicName
}

// clusterIsInKubeConfig checks if we have a context with the specified name (cluster name) in ~/.kube/config.
// It is used as a check to see if this is (likely) a new cluster.
func clusterIsInKubeConfig(contextName string) (bool, error) {
	configAccess := clientcmd.NewDefaultPathOptions()
	config, err := configAccess.GetStartingConfig()
	if err != nil {
		return false, fmt.Errorf("error reading kubeconfig: %w", err)
	}

	for k := range config.Contexts {
		if k == contextName {
			return true, nil
		}
	}

	return false, nil
}

func completeUpdateClusterTarget(f commandutils.Factory, options *CoreUpdateClusterOptions) func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
	return func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
		ctx := cmd.Context()

		commandutils.ConfigureKlogForCompletion()

		cluster, _, _, directive := GetClusterForCompletion(ctx, f, nil)

View on GitHub (pinned to 4c8573c808)

Solutions

  1. Check that ~/.kube/config exists and is valid YAML
  2. Set KUBECONFIG explicitly to a readable file
  3. Regenerate the kubeconfig with kops export kubecfg
Defensive patterns

Strategy: try-catch

When it happens

Trigger: Thrown at cmd/kops/update_cluster.go:539 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of kubernetes/kops@4c8573c808 (2026-09-05). Data as JSON: /api/errors/030d86a9d2edb948. Report an issue: GitHub.