kubernetes/kops · error

error parsing selector %v: %w

Error message

error parsing selector %v: %w

What it means

buildPruneDirectives constructs a fixed label selector (managed-by=kops plus the addon name) used for pruning old addon objects. The selector is validated with labels.ValidatedSelectorFromSet; if invalid, this error is returned with the offending map.

Source

Thrown at upup/pkg/fi/cloudup/bootstrapchannelbuilder/pruning.go:43

	"k8s.io/apimachinery/pkg/util/sets"
	"k8s.io/klog/v2"

	channelsapi "k8s.io/kops/channels/pkg/api"
	"k8s.io/kops/pkg/kubemanifest"
	"k8s.io/kops/pkg/model/components/addonmanifests"
)

func buildPruneDirectives(spec *channelsapi.AddonSpec, manifestData []byte) error {
	spec.Prune = &channelsapi.PruneSpec{}

	// We add these labels to all objects we manage, so we reuse them for pruning.
	selectorMap := map[string]string{
		"app.kubernetes.io/managed-by":   "kops",
		addonmanifests.KopsAddonLabelKey: *spec.Name,
	}
	selector, err := labels.ValidatedSelectorFromSet(selectorMap)
	if err != nil {
		return fmt.Errorf("error parsing selector %v: %w", selectorMap, err)
	}

	// We always include a set of well-known group kinds,
	// so that we prune even if we end up removing something from the manifest.
	alwaysPruneGroupKinds := []schema.GroupKind{
		{Group: "", Kind: "ConfigMap"},
		{Group: "", Kind: "Service"},
		{Group: "", Kind: "ServiceAccount"},
		{Group: "admissionregistration.k8s.io", Kind: "MutatingWebhookConfiguration"},
		{Group: "admissionregistration.k8s.io", Kind: "ValidatingWebhookConfiguration"},
		{Group: "apps", Kind: "Deployment"},
		{Group: "apps", Kind: "DaemonSet"},
		{Group: "apps", Kind: "StatefulSet"},
		{Group: "rbac.authorization.k8s.io", Kind: "ClusterRole"},
		{Group: "rbac.authorization.k8s.io", Kind: "ClusterRoleBinding"},
		{Group: "rbac.authorization.k8s.io", Kind: "Role"},
		{Group: "rbac.authorization.k8s.io", Kind: "RoleBinding"},
		{Group: "policy", Kind: "PodDisruptionBudget"},

View on GitHub (pinned to 4c8573c808)

Solutions

  1. Set the addon name in the manifest: spec.Name must be a non-empty valid label value
  2. Validate the addon manifest name field before building
  3. Fix the channel YAML so the addon has a proper name
  4. Use kops toolkit tools to verify addon manifest schema

Example fix

// before (addon manifest)
spec:
  # name missing
  version: 1.0.0
// after
spec:
  name: my-addon
  version: 1.0.0
Defensive patterns

Strategy: validation

Validate before calling

// Verify addon name is a valid label value before Normalize
if spec.Name == nil || *spec.Name == "" {
    return errors.New("addon spec.name required for prune directives")
}
if errs := validation.IsValidLabelValue(*spec.Name); len(errs) > 0 {
    return fmt.Errorf("invalid addon name %q: %v", *spec.Name, errs)
}

Try / catch

selector, err := labels.ValidatedSelectorFromSet(selectorMap)
if err != nil {
    return fmt.Errorf("addon manifest name invalid; set spec.name: %w", err)
}

Prevention

When it happens

Trigger: An addon spec with an empty or nil Name pointer (making *spec.Name invalid in the selector set) while Normalizing an AddonManifest and computing prune directives.

Common situations: Addon manifests missing the required 'name' field; programmatically built addon specs that omit Name; channel files corrupted or truncated.

Related errors


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