Skip to content

Commit

Permalink
Merge pull request #125809 from aojea/cloud_hostname
Browse files Browse the repository at this point in the history
add unit tests for hostname node.status.addresses

Kubernetes-commit: ef8d67f86528331d09c1de5ce4abb07b904ffd47
  • Loading branch information
k8s-publishing-bot committed Jul 18, 2024
2 parents cc641b6 + 6e5510e commit b60a8ce
Show file tree
Hide file tree
Showing 3 changed files with 163 additions and 15 deletions.
148 changes: 148 additions & 0 deletions controllers/node/node_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,154 @@ func Test_syncNode(t *testing.T) {
updatedNode *v1.Node
expectedErr bool
}{
{
name: "node initialized with hostname",
fakeCloud: &fakecloud.Cloud{
EnableInstancesV2: false,
InstanceTypes: map[types.NodeName]string{
types.NodeName("node0"): "t1.micro",
},
ExtID: map[types.NodeName]string{
types.NodeName("node0"): "12345",
},
Addresses: []v1.NodeAddress{
{
Type: v1.NodeHostName,
Address: "node0.cloud.internal",
},
{
Type: v1.NodeInternalIP,
Address: "10.0.0.1",
},
{
Type: v1.NodeExternalIP,
Address: "132.143.154.163",
},
},
ErrByProviderID: nil,
Err: nil,
},
existingNode: &v1.Node{
ObjectMeta: metav1.ObjectMeta{
Name: "node0",
CreationTimestamp: metav1.Date(2012, 1, 1, 0, 0, 0, 0, time.UTC),
},
Spec: v1.NodeSpec{
Taints: []v1.Taint{
{
Key: cloudproviderapi.TaintExternalCloudProvider,
Value: "true",
Effect: v1.TaintEffectNoSchedule,
},
},
},
Status: v1.NodeStatus{
Addresses: []v1.NodeAddress{
{
Type: v1.NodeHostName,
Address: "nodeoverriden",
},
},
},
},
updatedNode: &v1.Node{
ObjectMeta: metav1.ObjectMeta{
Name: "node0",
CreationTimestamp: metav1.Date(2012, 1, 1, 0, 0, 0, 0, time.UTC),
},
Spec: v1.NodeSpec{
ProviderID: "fake://12345",
},
Status: v1.NodeStatus{
Addresses: []v1.NodeAddress{
{
Type: v1.NodeHostName,
Address: "node0.cloud.internal",
},
{
Type: v1.NodeInternalIP,
Address: "10.0.0.1",
},
{
Type: v1.NodeExternalIP,
Address: "132.143.154.163",
},
},
},
},
},
{
name: "node initialized with hostname and cloud provider missing hostname",
fakeCloud: &fakecloud.Cloud{
EnableInstancesV2: false,
InstanceTypes: map[types.NodeName]string{
types.NodeName("node0"): "t1.micro",
},
ExtID: map[types.NodeName]string{
types.NodeName("node0"): "12345",
},
Addresses: []v1.NodeAddress{
{
Type: v1.NodeInternalIP,
Address: "10.0.0.1",
},
{
Type: v1.NodeExternalIP,
Address: "132.143.154.163",
},
},
ErrByProviderID: nil,
Err: nil,
},
existingNode: &v1.Node{
ObjectMeta: metav1.ObjectMeta{
Name: "node0",
CreationTimestamp: metav1.Date(2012, 1, 1, 0, 0, 0, 0, time.UTC),
},
Spec: v1.NodeSpec{
Taints: []v1.Taint{
{
Key: cloudproviderapi.TaintExternalCloudProvider,
Value: "true",
Effect: v1.TaintEffectNoSchedule,
},
},
},
Status: v1.NodeStatus{
Addresses: []v1.NodeAddress{
{
Type: v1.NodeHostName,
Address: "nodeoverriden",
},
},
},
},
updatedNode: &v1.Node{
ObjectMeta: metav1.ObjectMeta{
Name: "node0",
CreationTimestamp: metav1.Date(2012, 1, 1, 0, 0, 0, 0, time.UTC),
},
Spec: v1.NodeSpec{
ProviderID: "fake://12345",
},
Status: v1.NodeStatus{
Addresses: []v1.NodeAddress{
{
Type: v1.NodeInternalIP,
Address: "10.0.0.1",
},
{
Type: v1.NodeExternalIP,
Address: "132.143.154.163",
},
{
Type: v1.NodeHostName,
Address: "nodeoverriden",
},
},
},
},
},
{
name: "node initialized with provider ID",
fakeCloud: &fakecloud.Cloud{
Expand Down
10 changes: 5 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ require (
github.com/spf13/cobra v1.8.1
github.com/spf13/pflag v1.0.5
github.com/stretchr/testify v1.9.0
k8s.io/api v0.0.0-20240713182828-fc8a03c10db3
k8s.io/apimachinery v0.0.0-20240713182533-d7e1c5311169
k8s.io/apiserver v0.0.0-20240713185020-2e2bf0d3280c
k8s.io/client-go v0.0.0-20240713183232-34751e103ae1
k8s.io/component-base v0.0.0-20240713184224-e801fe99c4f5
k8s.io/api v0.0.0-20240716223232-b1818c55a2cf
k8s.io/apimachinery v0.0.0-20240715201109-ab0686929a37
k8s.io/apiserver v0.0.0-20240717191006-1ae379291411
k8s.io/client-go v0.0.0-20240716224050-37121f3f0017
k8s.io/component-base v0.0.0-20240715183844-6f32dbe8ef25
k8s.io/component-helpers v0.0.0-20240713184356-f77f7fa6cffb
k8s.io/controller-manager v0.0.0-20240713191611-d6bb17e0c723
k8s.io/klog/v2 v2.130.1
Expand Down
20 changes: 10 additions & 10 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -277,16 +277,16 @@ gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
k8s.io/api v0.0.0-20240713182828-fc8a03c10db3 h1:/HdJNMoAomKcMa1p3ei3yF65O36bO3+9VzcZMU1Xn6o=
k8s.io/api v0.0.0-20240713182828-fc8a03c10db3/go.mod h1:P1YOh3DKAaEYfUIAqsGSOKkLqz7k6Z8eORxlNIDQD0E=
k8s.io/apimachinery v0.0.0-20240713182533-d7e1c5311169 h1:uUu5XUsiHPkOU48Bn2d2DoqUQDG9Y02fD43VqYbagPI=
k8s.io/apimachinery v0.0.0-20240713182533-d7e1c5311169/go.mod h1:rsPdaZJfTfLsNJSQzNHQvYoTmxhoOEofxtOsF3rtsMo=
k8s.io/apiserver v0.0.0-20240713185020-2e2bf0d3280c h1:b21+nDcmvjK0kHFpFCJLS1TRZlj3fn2RBPc6rHRWKss=
k8s.io/apiserver v0.0.0-20240713185020-2e2bf0d3280c/go.mod h1:qzIE/w79am4BEOJGb1ew2EfIo9NgPx6k3boT8UAzgAU=
k8s.io/client-go v0.0.0-20240713183232-34751e103ae1 h1:g2031r79lLso9fNr/KbU83GAsOjFyLAI3JGX7Xdr3gI=
k8s.io/client-go v0.0.0-20240713183232-34751e103ae1/go.mod h1:4MV9/0pbyHXOkdxPNA5dI3+KKKqNfqA4BijKqKDjN/U=
k8s.io/component-base v0.0.0-20240713184224-e801fe99c4f5 h1:73I6ThMvA3JjmRwgx4zyi2fH3BVTq4a8mfOEE7wHakM=
k8s.io/component-base v0.0.0-20240713184224-e801fe99c4f5/go.mod h1:jZywpxGEvQNFuHHJWMaxWO41SOnN6pqd40f0nWjy/J0=
k8s.io/api v0.0.0-20240716223232-b1818c55a2cf h1:cbzpVluJQA7itGwCQfOtrN7lC0zyraDcNEUeSNR8JuA=
k8s.io/api v0.0.0-20240716223232-b1818c55a2cf/go.mod h1:2UcZQyUkPm7CMfP50V/oCVagw0chxcTd2M0sBNxxM9E=
k8s.io/apimachinery v0.0.0-20240715201109-ab0686929a37 h1:vG4p9Dp1oF1azqq+OvpzZjVtlKqo91bRDoZ2MfgoUaw=
k8s.io/apimachinery v0.0.0-20240715201109-ab0686929a37/go.mod h1:rsPdaZJfTfLsNJSQzNHQvYoTmxhoOEofxtOsF3rtsMo=
k8s.io/apiserver v0.0.0-20240717191006-1ae379291411 h1:okRFa1enwoGLK/VrUmQIwMQH34xrX7FwNhQ32BMRbrU=
k8s.io/apiserver v0.0.0-20240717191006-1ae379291411/go.mod h1:Gb8l02Z0DqGi/EkVcrunBXcfiu179UaWDo5iELp2YmU=
k8s.io/client-go v0.0.0-20240716224050-37121f3f0017 h1:JEgVscZsh/yV2pNME86uL2m6fiA4fLG1rCJaps89uoo=
k8s.io/client-go v0.0.0-20240716224050-37121f3f0017/go.mod h1:zL7YF5NjMS73vImwwq3QFNw6KzshOa9v2twgw9WQwoI=
k8s.io/component-base v0.0.0-20240715183844-6f32dbe8ef25 h1:9SIVS17h6glmGM2G4ILkpQRUYc/zZ7y15gD2uaby0rM=
k8s.io/component-base v0.0.0-20240715183844-6f32dbe8ef25/go.mod h1:YYWVx/ele54LQcShCdQpmsIqiHgZ+KjWY7WGMzTjKGk=
k8s.io/component-helpers v0.0.0-20240713184356-f77f7fa6cffb h1:klgEnJlSj867TrU7c2RBXdxuNdBklpwZxOJHHsKP5x8=
k8s.io/component-helpers v0.0.0-20240713184356-f77f7fa6cffb/go.mod h1:T/wlkd8Q5SQXhqWJt2x1HD2GTAQ9eysgwNbWLMOEipA=
k8s.io/controller-manager v0.0.0-20240713191611-d6bb17e0c723 h1:/35JxiOJASltRMap7lpG2WnmjQ3s5O/lfK4PME8wWro=
Expand Down

0 comments on commit b60a8ce

Please sign in to comment.