Skip to content
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

Ko 461 nodeport service v2 #177

Merged
merged 16 commits into from
Jul 28, 2020
Merged

Ko 461 nodeport service v2 #177

merged 16 commits into from
Jul 28, 2020

Conversation

respringer
Copy link
Collaborator

@respringer respringer commented Jul 28, 2020

A NodePort service may be requested by setting the following fields:

  networking:
    nodePort:
      cql: 30001
      broadcast: 30002

The SSL versions of the ports may be requested:

  networking:
    nodePort:
      cqlSSL: 30010
      broadcastSSL: 30020

If any of the nodePort fields have been configured then a NodePort service will be created that routes from the specified external port to the identically numbered internal port. Cassandra will be configured to listen on the specified ports. Additionally, the standard service will no longer define a "native" port.

Comment on lines 379 to 380
cqlSql: 30010
broadcastSql: 30020
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
cqlSql: 30010
broadcastSql: 30020
cqlSsl: 30010
broadcastSsl: 30020

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and actually maybe SSL should be in caps, because golang idioms

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doh!

@@ -369,3 +367,27 @@ func (ns NsWrapper) HelmInstall(chartPath string) {
err := helm_util.Install(chartPath, "cass-operator", ns.Namespace, overrides)
mageutil.PanicOnError(err)
}

// Note that the actual value will be cast to a string before the comparison with the expectedValue
func (ns NsWrapper) ExpectKeyValue(m map[string]interface{}, key string, expectedValue string) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ExpectKeyValues(), which takes a whole map, and the helper function ExpectKeyValue() are a first-pass at a generic way to validate key/values. Right now everything is cast to a string. I added a helper for dealing with Float64 values because the Ports from the service were coming back as Float64s for some reason. I am open to suggestion for improvements, but we may want to handle them in a follow-up ticket.

return 0
}

if dc.Spec.Networking.NodePort.BroadcastSsl != 0 {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The port fallback logic is a bit squirrelly and went through multiple designs via slack/standup conversations. What I have landed on is nodeport ssl ports take first priority, then nodeport non-ssl ports, then the defaults of 9042 for native and 7000 for broadcast. If the nodeport native/cql port is defined, then the native port will be omitted from the normal service.

{
Name: "mgmt-api", Port: 8080, TargetPort: intstr.FromInt(8080),
},
}

// If NodePort is enabled, it will take control of the native port
if !dc.IsNodePortEnabled() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why disable this when node port is configured vs just put the port number here? I think taking it out might break some folks with in cluster clients

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will put it back.

TargetPort: intstr.FromInt(broadcastPort),
},
{
Name: "native",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JeremiahDJordan do you think cql is a better name here? what about broadcast vs. internode?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Broadcast is wrong. I would call it internode. Both internode and native protocol (cql) ports have broadcast settings.

Copy link
Collaborator

@jimdickinson jimdickinson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

networking:
nodePort:
cqlSql: 30010
broadcastSql: 30020
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

broadcastSsl?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was a typo. I pushed a fix.


// Note that the actual value will be cast to a string before the comparison with the expectedValue
func (ns NsWrapper) ExpectKeyValue(m map[string]interface{}, key string, expectedValue string) {
actualValue, ok := m[key].(string)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I understand the intent of this code correctly, I don't think it works the way you expect. Floats, ints, etc. cannot be cast to strings in this manner:

https://play.golang.org/p/lIg2pmmYczZ

You would have to parse them.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This tries to interpret the value as a string. If that was possible, then ok is set to true. If that was not possible, for instance, the value was a float64, then ok is set to false.

// GetContainerPorts will return the container ports for the pods in a statefulset based on the provided config
func (dc *CassandraDatacenter) GetContainerPorts() ([]corev1.ContainerPort, error) {

cqlPort := 9042
broadcastPort := 7000
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be time to make these constants somewhere. Like defaultCqlPort or something.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea, I will do that.

@johntrimble
Copy link
Collaborator

By the way, the PR looks great!

@respringer respringer merged commit b2cf2ec into master Jul 28, 2020
@respringer respringer deleted the KO-461-nodeport-service-v2 branch July 28, 2020 21:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants