-
Notifications
You must be signed in to change notification settings - Fork 323
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
peering: support setting externalServers hosts in peering token for non-default partitions #1384
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
2f0aadd
default partitions works with load balancer service
ndhanushkodi 8469180
working config for non-default aps
ndhanushkodi c43d53b
support externalServers' addresses being set in the token for peering…
ndhanushkodi c27bcce
remove peering test config
ndhanushkodi dd879c7
add consul binaries to use before next consul release
ndhanushkodi d8b305b
bump sdk version
ndhanushkodi 712e659
address review comment, cleanup
ndhanushkodi 290116f
update port in unit tests
ndhanushkodi 5d563f9
use consul binary without peering secrets
ndhanushkodi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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 |
---|---|---|
|
@@ -29,14 +29,17 @@ func TestReconcile_CreateUpdatePeeringAcceptor(t *testing.T) { | |
t.Parallel() | ||
nodeName := "test-node" | ||
cases := []struct { | ||
name string | ||
k8sObjects func() []runtime.Object | ||
expectedConsulPeerings []*api.Peering | ||
expectedK8sSecrets func() []*corev1.Secret | ||
expErr string | ||
expectedStatus *v1alpha1.PeeringAcceptorStatus | ||
expectDeletedK8sSecret *types.NamespacedName | ||
initialConsulPeerName string | ||
name string | ||
k8sObjects func() []runtime.Object | ||
expectedConsulPeerings []*api.Peering | ||
expectedK8sSecrets func() []*corev1.Secret | ||
expErr string | ||
expectedStatus *v1alpha1.PeeringAcceptorStatus | ||
expectDeletedK8sSecret *types.NamespacedName | ||
initialConsulPeerName string | ||
externalAddresses []string | ||
readServerExposeService bool | ||
expectedTokenAddresses []string | ||
}{ | ||
{ | ||
name: "New PeeringAcceptor creates a peering in Consul and generates a token", | ||
|
@@ -85,6 +88,122 @@ func TestReconcile_CreateUpdatePeeringAcceptor(t *testing.T) { | |
return []*corev1.Secret{secret} | ||
}, | ||
}, | ||
{ | ||
name: "PeeringAcceptor generates a token with expose server addresses", | ||
readServerExposeService: true, | ||
expectedTokenAddresses: []string{"1.1.1.1:8503"}, | ||
k8sObjects: func() []runtime.Object { | ||
service := &corev1.Service{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "test-expose-servers", | ||
Namespace: "default", | ||
}, | ||
Spec: corev1.ServiceSpec{ | ||
Type: corev1.ServiceTypeLoadBalancer, | ||
}, | ||
Status: corev1.ServiceStatus{ | ||
LoadBalancer: corev1.LoadBalancerStatus{ | ||
Ingress: []corev1.LoadBalancerIngress{ | ||
{ | ||
IP: "1.1.1.1", | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
acceptor := &v1alpha1.PeeringAcceptor{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "acceptor-created", | ||
Namespace: "default", | ||
}, | ||
Spec: v1alpha1.PeeringAcceptorSpec{ | ||
Peer: &v1alpha1.Peer{ | ||
Secret: &v1alpha1.Secret{ | ||
Name: "acceptor-created-secret", | ||
Key: "data", | ||
Backend: "kubernetes", | ||
}, | ||
}, | ||
}, | ||
} | ||
return []runtime.Object{acceptor, service} | ||
}, | ||
expectedStatus: &v1alpha1.PeeringAcceptorStatus{ | ||
SecretRef: &v1alpha1.SecretRefStatus{ | ||
Secret: v1alpha1.Secret{ | ||
Name: "acceptor-created-secret", | ||
Key: "data", | ||
Backend: "kubernetes", | ||
}, | ||
}, | ||
}, | ||
expectedConsulPeerings: []*api.Peering{ | ||
{ | ||
Name: "acceptor-created", | ||
}, | ||
}, | ||
expectedK8sSecrets: func() []*corev1.Secret { | ||
secret := &corev1.Secret{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "acceptor-created-secret", | ||
Namespace: "default", | ||
}, | ||
StringData: map[string]string{ | ||
"data": "tokenstub", | ||
}, | ||
} | ||
return []*corev1.Secret{secret} | ||
}, | ||
}, | ||
{ | ||
name: "PeeringAcceptor generates a token with external addresses specified", | ||
externalAddresses: []string{"1.1.1.1:8503", "2.2.2.2:8503"}, | ||
expectedTokenAddresses: []string{"1.1.1.1:8503", "2.2.2.2:8503"}, | ||
k8sObjects: func() []runtime.Object { | ||
acceptor := &v1alpha1.PeeringAcceptor{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "acceptor-created", | ||
Namespace: "default", | ||
}, | ||
Spec: v1alpha1.PeeringAcceptorSpec{ | ||
Peer: &v1alpha1.Peer{ | ||
Secret: &v1alpha1.Secret{ | ||
Name: "acceptor-created-secret", | ||
Key: "data", | ||
Backend: "kubernetes", | ||
}, | ||
}, | ||
}, | ||
} | ||
return []runtime.Object{acceptor} | ||
}, | ||
expectedStatus: &v1alpha1.PeeringAcceptorStatus{ | ||
SecretRef: &v1alpha1.SecretRefStatus{ | ||
Secret: v1alpha1.Secret{ | ||
Name: "acceptor-created-secret", | ||
Key: "data", | ||
Backend: "kubernetes", | ||
}, | ||
}, | ||
}, | ||
expectedConsulPeerings: []*api.Peering{ | ||
{ | ||
Name: "acceptor-created", | ||
}, | ||
}, | ||
expectedK8sSecrets: func() []*corev1.Secret { | ||
secret := &corev1.Secret{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "acceptor-created-secret", | ||
Namespace: "default", | ||
}, | ||
StringData: map[string]string{ | ||
"data": "tokenstub", | ||
}, | ||
} | ||
return []*corev1.Secret{secret} | ||
}, | ||
}, | ||
{ | ||
name: "When the secret already exists (not created by controller), it is updated with the contents of the new peering token and an owner reference is added", | ||
k8sObjects: func() []runtime.Object { | ||
|
@@ -424,10 +543,14 @@ func TestReconcile_CreateUpdatePeeringAcceptor(t *testing.T) { | |
|
||
// Create the peering acceptor controller | ||
controller := &PeeringAcceptorController{ | ||
Client: fakeClient, | ||
Log: logrtest.TestLogger{T: t}, | ||
ConsulClient: consulClient, | ||
Scheme: s, | ||
Client: fakeClient, | ||
TokenServerAddresses: tt.externalAddresses, | ||
ReadServerExternalService: tt.readServerExposeService, | ||
ExposeServersServiceName: "test-expose-servers", | ||
ReleaseNamespace: "default", | ||
Log: logrtest.TestLogger{T: t}, | ||
ConsulClient: consulClient, | ||
Scheme: s, | ||
} | ||
namespacedName := types.NamespacedName{ | ||
Name: "acceptor-created", | ||
|
@@ -475,6 +598,11 @@ func TestReconcile_CreateUpdatePeeringAcceptor(t *testing.T) { | |
require.Contains(t, string(decodedTokenData), "\"CA\":null") | ||
require.Contains(t, string(decodedTokenData), "\"ServerAddresses\"") | ||
require.Contains(t, string(decodedTokenData), "\"ServerName\":\"server.dc1.consul\"") | ||
if len(tt.expectedTokenAddresses) > 0 { | ||
for _, addr := range tt.externalAddresses { | ||
require.Contains(t, string(decodedTokenData), addr) | ||
} | ||
} | ||
Comment on lines
+601
to
+605
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ❤️ |
||
|
||
// Get the reconciled PeeringAcceptor and make assertions on the status | ||
acceptor := &v1alpha1.PeeringAcceptor{} | ||
|
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
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not a blocker, but we should probably fail if you provide a value that we don't support
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will add this in the last stacked PR, so we can fail on values that are not "static" or "consul" or ""
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added to the 3rd of the stacked PRs!