kubernetes/kops · error

failed to parse objects: %w

Error message

failed to parse objects: %w

What it means

Pruner.Prune parses the addon manifest with kubemanifest.LoadObjectsFrom to know which objects must be kept. If the manifest is not valid YAML/JSON or does not decode into Kubernetes objects, the parse error is wrapped as `failed to parse objects`. Pruning aborts before any cluster mutation.

Source

Thrown at channels/pkg/channels/prune.go:48

	"k8s.io/kops/pkg/kubemanifest"
)

type Pruner struct {
	Client     dynamic.Interface
	RESTMapper *restmapper.DeferredDiscoveryRESTMapper
}

// Prune prunes objects not in the manifest, according to PruneSpec.
func (p *Pruner) Prune(ctx context.Context, manifest []byte, spec *api.PruneSpec) error {
	klog.Infof("Prune spec: %v", spec)

	if spec == nil {
		return nil
	}

	objects, err := kubemanifest.LoadObjectsFrom(manifest)
	if err != nil {
		return fmt.Errorf("failed to parse objects: %w", err)
	}

	objectsByKind := make(map[schema.GroupKind][]*kubemanifest.Object)
	for _, object := range objects {
		gv, err := schema.ParseGroupVersion(object.APIVersion())
		if err != nil || gv.Version == "" {
			return fmt.Errorf("failed to parse apiVersion %q", object.APIVersion())
		}
		kind := object.Kind()
		if kind == "" {
			return fmt.Errorf("failed to find kind in object")
		}

		gvk := gv.WithKind(kind)
		gk := gvk.GroupKind()
		objectsByKind[gk] = append(objectsByKind[gk], object)
	}

View on GitHub (pinned to 4c8573c808)

Solutions

  1. Inspect the wrapped parse error to find the offending document/line
  2. Validate the manifest locally: `kubectl apply --dry-run=client -f manifest.yaml` or a YAML linter
  3. Fix or re-download the addon manifest from the channel source
  4. If the manifest is templated, ensure the template was fully rendered before Prune

Example fix

// before
kind:  Deployment
metadata: [broken yaml
// after
apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-deployment
Defensive patterns

Strategy: validation

Validate before calling

func validateManifest(manifest []byte) error {
    objs, err := kubemanifest.LoadObjectsFrom(manifest)
    if err != nil {
        return fmt.Errorf("manifest not parseable: %w", err)
    }
    if len(objs) == 0 {
        return fmt.Errorf("manifest contains no objects")
    }
    return nil
}
// call validateManifest(data) before Prune

Try / catch

if err := pruner.Prune(ctx, manifest, spec); err != nil {
    if strings.Contains(err.Error(), "failed to parse objects") {
        return fmt.Errorf("addon manifest corrupt, skip prune: %w", err)
    }
    return err
}

Prevention

When it happens

Trigger: Prune is called (via updateAddon) with a manifest []byte that is malformed YAML, empty/garbage content, or contains documents that cannot be loaded as unstructured objects.

Common situations: Broken addon manifest in the channel (bad indentation, tabs, truncated download from S3); a multi-doc file with a stray non-YAML document; templating left unrendered placeholders ({{ }}) in the manifest.

Understand the failure class

Related errors


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