-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update endpoint IP selection order based on address type found (#61)
Signed-off-by: Rahul Ganesh <[email protected]> Co-authored-by: Rahul Ganesh <[email protected]>
- Loading branch information
1 parent
b202824
commit a407200
Showing
2 changed files
with
116 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
package controllers | ||
|
||
import ( | ||
"testing" | ||
|
||
. "github.com/onsi/gomega" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" | ||
) | ||
|
||
func TestGetEtcdMachineAddress(t *testing.T) { | ||
g := NewWithT(t) | ||
type test struct { | ||
machine clusterv1.Machine | ||
AvailAddrTypes clusterv1.MachineAddresses | ||
wantAddr string | ||
} | ||
|
||
capiMachine := clusterv1.Machine{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "machine", | ||
}, | ||
Spec: clusterv1.MachineSpec{ | ||
ClusterName: "test-cluster", | ||
}, | ||
Status: clusterv1.MachineStatus{}, | ||
} | ||
tests := []test{ | ||
{ | ||
machine: capiMachine, | ||
AvailAddrTypes: clusterv1.MachineAddresses{ | ||
clusterv1.MachineAddress{ | ||
Type: clusterv1.MachineInternalIP, | ||
Address: "1.1.1.1", | ||
}, clusterv1.MachineAddress{ | ||
Type: clusterv1.MachineExternalIP, | ||
Address: "2.2.2.2", | ||
}, | ||
}, | ||
wantAddr: "2.2.2.2", | ||
}, { | ||
machine: capiMachine, | ||
AvailAddrTypes: []clusterv1.MachineAddress{ | ||
{ | ||
Type: clusterv1.MachineInternalDNS, | ||
Address: "1.1.1.1", | ||
}, { | ||
Type: clusterv1.MachineExternalIP, | ||
Address: "2.2.2.2", | ||
}, | ||
}, | ||
wantAddr: "2.2.2.2", | ||
}, { | ||
machine: capiMachine, | ||
AvailAddrTypes: []clusterv1.MachineAddress{ | ||
{ | ||
Type: clusterv1.MachineInternalIP, | ||
Address: "1.1.1.1", | ||
}, { | ||
Type: clusterv1.MachineInternalDNS, | ||
Address: "2.2.2.2", | ||
}, | ||
}, | ||
wantAddr: "2.2.2.2", | ||
}, { | ||
machine: capiMachine, | ||
AvailAddrTypes: []clusterv1.MachineAddress{ | ||
{ | ||
Type: clusterv1.MachineExternalDNS, | ||
Address: "1.1.1.1", | ||
}, { | ||
Type: clusterv1.MachineInternalDNS, | ||
Address: "2.2.2.2", | ||
}, | ||
}, | ||
wantAddr: "1.1.1.1", | ||
}, { | ||
machine: capiMachine, | ||
AvailAddrTypes: []clusterv1.MachineAddress{ | ||
{ | ||
Type: clusterv1.MachineHostName, | ||
Address: "1.1.1.1", | ||
}, | ||
}, | ||
wantAddr: "", | ||
}, | ||
} | ||
for _, tc := range tests { | ||
capiMachine.Status.Addresses = tc.AvailAddrTypes | ||
g.Expect(getEtcdMachineAddress(&capiMachine)).To(Equal(tc.wantAddr)) | ||
} | ||
} |