kubernetes/kops · error

MockDNS not set

Error message

MockDNS not set

What it means

The mock OpenStack cloud was asked to perform a DNS operation but its MockDNS field was never populated by the test. It is a sentinel-style guard: the test fixture is incomplete, not a production failure.

Source

Thrown at upup/pkg/fi/cloudup/openstack/mock_cloud.go:151

func (c *MockCloud) DeregisterInstance(i *cloudinstances.CloudInstance) error {
	return deregisterInstance(c, i.ID)
}

func (c *MockCloud) DetachInstance(i *cloudinstances.CloudInstance) error {
	return detachInstance(c, i)
}

func (c *MockCloud) GetCloudGroups(cluster *kops.Cluster, instancegroups []*kops.InstanceGroup, warnUnmatched bool, nodes []v1.Node) (map[string]*cloudinstances.CloudInstanceGroup, error) {
	return getCloudGroups(c, cluster, instancegroups, warnUnmatched, nodes)
}

func (c *MockCloud) ProviderID() kops.CloudProviderID {
	return kops.CloudProviderOpenstack
}

func (c *MockCloud) DNS() (dnsprovider.Interface, error) {
	if c.MockDNSClient == nil {
		return nil, fmt.Errorf("MockDNS not set")
	}
	return dnsproviderdesignate.New(c.DNSClient()), nil
}

func (c *MockCloud) FindVPCInfo(id string) (*fi.VPCInfo, error) {
	return findVPCInfo(c, id, c.zones)
}

func (c *MockCloud) Region() string {
	return c.region
}

func (c *MockCloud) AppendTag(resource string, id string, tag string) error {
	return appendTag(c, resource, id, tag)
}

func (c *MockCloud) AssociateToPool(server *servers.Server, poolID string, opts v2pools.CreateMemberOpts) (association *v2pools.Member, err error) {
	return associateToPool(c, server, poolID, opts)

View on GitHub (pinned to 4c8573c808)

Example fix

// before
cloud := openstack.NewMockCloud(t)
_ = cloud.DNS()
// after
cloud := openstack.NewMockCloud(t)
cloud.MockDNSClient = ... // init mock DNS client
_ = cloud.DNS()
Defensive patterns

Strategy: validation

Validate before calling

if cloud.MockDNSClient == nil {
    t.Fatal("MockDNSClient must be initialized before test")
}

Type guard

func hasMockDNS(c *openstack.MockCloud) bool { return c.MockDNSClient != nil }

Prevention

When it happens

Trigger: Calling DNS() on a MockCloud built by newMockCloud without first assigning c.MockDNSClient.

Common situations: Unit tests of OpenStack DNS/designate integration using the mock cloud but forgetting to set the designate client; refactors that call DNS() in code paths tests did not previously cover.

Related errors


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