-
Notifications
You must be signed in to change notification settings - Fork 66
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
Expose the new metrics port in the all-pods service #489
Merged
Merged
Changes from all commits
Commits
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ import ( | |
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
corev1 "k8s.io/api/core/v1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
|
||
api "github.com/k8ssandra/cass-operator/apis/cassandra/v1beta1" | ||
|
@@ -407,3 +408,99 @@ func TestAddingAdditionalLabels(t *testing.T) { | |
t.Errorf("service labels = %v, want %v", service.Labels, expected) | ||
} | ||
} | ||
|
||
func TestServicePorts(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
dc *api.CassandraDatacenter | ||
dcServicePorts []int32 | ||
allPodsServicePorts []int32 | ||
}{ | ||
{ | ||
name: "Cassandra 3.11.14", | ||
dc: &api.CassandraDatacenter{ | ||
Spec: api.CassandraDatacenterSpec{ | ||
ClusterName: "bob", | ||
ServerType: "cassandra", | ||
ServerVersion: "3.11.14", | ||
}, | ||
}, | ||
dcServicePorts: []int32{8080, 9000, 9042, 9103, 9142, 9160}, | ||
allPodsServicePorts: []int32{8080, 9000, 9042, 9103}, | ||
}, | ||
{ | ||
name: "Cassandra 4.0.7", | ||
dc: &api.CassandraDatacenter{ | ||
Spec: api.CassandraDatacenterSpec{ | ||
ClusterName: "bob", | ||
ServerType: "cassandra", | ||
ServerVersion: "4.0.7", | ||
}, | ||
}, | ||
dcServicePorts: []int32{8080, 9000, 9042, 9103, 9142}, | ||
allPodsServicePorts: []int32{8080, 9000, 9042, 9103}, | ||
}, | ||
{ | ||
name: "DSE 6.8.31", | ||
dc: &api.CassandraDatacenter{ | ||
Spec: api.CassandraDatacenterSpec{ | ||
ClusterName: "bob", | ||
ServerType: "dse", | ||
ServerVersion: "6.8.31", | ||
}, | ||
}, | ||
dcServicePorts: []int32{8080, 9000, 9042, 9103, 9142, 9160}, | ||
allPodsServicePorts: []int32{8080, 9000, 9042, 9103}, | ||
}, | ||
{ | ||
name: "Cassandra 4.0.7 with custom ports", | ||
dc: &api.CassandraDatacenter{ | ||
Spec: api.CassandraDatacenterSpec{ | ||
ClusterName: "bob", | ||
ServerType: "cassandra", | ||
ServerVersion: "4.0.7", | ||
PodTemplateSpec: &corev1.PodTemplateSpec{ | ||
Spec: corev1.PodSpec{ | ||
Containers: []corev1.Container{ | ||
{ | ||
Name: "cassandra", | ||
Ports: []corev1.ContainerPort{ | ||
{ | ||
Name: "metrics", | ||
ContainerPort: 9004, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
// FIXME: 9004 should be in the list of open ports | ||
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. This is interesting: I copied this test from |
||
dcServicePorts: []int32{8080, 9000, 9042, 9103, 9142}, | ||
allPodsServicePorts: []int32{8080, 9000, 9042, 9103}, | ||
}, | ||
} | ||
|
||
for _, test := range tests { | ||
t.Run(test.name, func(t *testing.T) { | ||
var getServicePorts = func(svc *corev1.Service) []int32 { | ||
servicePorts := make([]int32, len(svc.Spec.Ports)) | ||
for i := 0; i < len(svc.Spec.Ports); i++ { | ||
servicePorts[i] = svc.Spec.Ports[i].Port | ||
} | ||
return servicePorts | ||
} | ||
t.Run("dc service", func(t *testing.T) { | ||
svc := newServiceForCassandraDatacenter(test.dc) | ||
servicePorts := getServicePorts(svc) | ||
assert.ElementsMatch(t, servicePorts, test.dcServicePorts) | ||
}) | ||
t.Run("all pods service", func(t *testing.T) { | ||
svc := newAllPodsServiceForCassandraDatacenter(test.dc) | ||
servicePorts := getServicePorts(svc) | ||
assert.ElementsMatch(t, servicePorts, test.allPodsServicePorts) | ||
}) | ||
}) | ||
} | ||
} |
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.
I wonder: shouldn't all-pods service expose the same ports as the dc service? But I didn't want to change that in this PR.
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.
it depends what the all-ports service is used for.
If no one expressed any requirement around that, I agree we shouldn't change it.
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.
From what I understand the all-pods service is identical to the dc service, but also includes pods not ready. So it's not suitable to be used as a contact point for the drivers, but it is useful for metrics for instance. Maybe that's the reason why it doesn't expose so many ports. That said, following this logic it shouldn't expose 9042 either. Anyways 🤷♂️
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.
cass-operator sets allPods as the ServiceName for all pods to ensure that they get DNS working correctly. Using only the dcPods would make the DNS names fail in certain cases:
#18