kubernetes/kops · error

expected RoleAssignment, but got %T

Error message

expected RoleAssignment, but got %T

What it means

A type assertion guard: deleteRoleAssignment finds the resource's Obj is not an *authz.RoleAssignment, meaning the resource tracker was built with the wrong object type — an internal invariant violation, not a user-input problem.

Source

Thrown at pkg/resources/azure/azure.go:646

	return &resources.Resource{
		Obj:     ra,
		Type:    typeRoleAssignment,
		ID:      *ra.ID,
		Name:    *ra.Name,
		Deleter: g.deleteRoleAssignment,
		Blocks: []string{
			toKey(typeResourceGroup, g.resourceGroupID()),
		},
		// Wait for the VMSS to be deleted before removing role assignments,
		// to avoid permission issues during VMSS teardown.
		Blocked: []string{toKey(typeVMScaleSet, *vmss.ID)},
	}
}

func (g *resourceGetter) deleteRoleAssignment(_ fi.Cloud, r *resources.Resource) error {
	ra, ok := r.Obj.(*authz.RoleAssignment)
	if !ok {
		return fmt.Errorf("expected RoleAssignment, but got %T", r)
	}
	return g.cloud.RoleAssignment().Delete(context.TODO(), *ra.Properties.Scope, *ra.Name)
}

func (g *resourceGetter) listLoadBalancers(ctx context.Context) ([]*resources.Resource, error) {
	loadBalancers, err := g.cloud.LoadBalancer().List(ctx, g.resourceGroupName())
	if err != nil {
		return nil, err
	}

	var rs []*resources.Resource
	for _, lb := range loadBalancers {
		if !g.isOwnedByCluster(lb.Tags) {
			continue
		}
		r, err := g.toLoadBalancerResource(lb)
		if err != nil {
			return nil, err

View on GitHub (pinned to 4c8573c808)

Solutions

  1. Check how the resource tracker was created — Obj should be *authz.RoleAssignment
  2. Report a kOps bug if this occurs with unmodified code
  3. Re-run discovery so the resource tracker is rebuilt with the correct type
Defensive patterns

Strategy: type-guard

When it happens

Trigger: Thrown at pkg/resources/azure/azure.go:646 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/b9da567208a3b37a. Report an issue: GitHub.