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

NetworkPolicyPort requires pointer to const for Protocol #333

Closed
donovansolms opened this issue Nov 28, 2017 · 4 comments
Closed

NetworkPolicyPort requires pointer to const for Protocol #333

donovansolms opened this issue Nov 28, 2017 · 4 comments
Labels
lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed.

Comments

@donovansolms
Copy link

I found an inconsistency for specifying the Protocol for ingress and egress network policies that requires a workaround since Go doesn't allow getting a const address directly.

Client Version: client-go 5.0
Kubernetes Version: 1.8

In other areas where you need to specify a protocol/port combination, such as ServicePort you can do:

v1.ServiceSpec{
	Ports: []v1.ServicePort{
		{
			Protocol: v1.ProtocolUDP, // Use the const directly
		},
	},
}

However, in NetworkPolicyPort you need to provide a pointer to the Protocol constant.

Ports: []networkv1.NetworkPolicyPort{
    {
        // This can't be done in Go directly
        // error: cannot take the address of "k8s.io/api/core/v1".ProtocolUDP
        Protocol: &v1.ProtocolUDP,
        Port: &intstr.IntOrString{
            Type:   intstr.Int,
            IntVal: int32(53),
        },
    },
},

To make this work you need to assign the const to a variable that you can get the address of and use that. This feels wrong to me.

const protocolConst = v1.ProtocolUDP
protocolVar := protocolConst

Ports: []networkv1.NetworkPolicyPort{
    {
        Protocol: &protocolVar,
        Port: &intstr.IntOrString{
            Type:   intstr.Int,
            IntVal: int32(53),
        },
    },
},

The differences can be found in core api/types and networking api/types.

This isn't really an issue as the code works as expected, it just requires an odd workaround to make it work. Am I missing something here? Is there a specific reason why this would require a pointer?

Note: I could not see any reason why it would be generated as such since there is no real difference in the protobuf definitions for NetworkPolicyPort and ServicePort

@fejta-bot
Copy link

Issues go stale after 90d of inactivity.
Mark the issue as fresh with /remove-lifecycle stale.
Stale issues rot after an additional 30d of inactivity and eventually close.

If this issue is safe to close now please do so with /close.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/lifecycle stale

@k8s-ci-robot k8s-ci-robot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Feb 26, 2018
@fejta-bot
Copy link

Stale issues rot after 30d of inactivity.
Mark the issue as fresh with /remove-lifecycle rotten.
Rotten issues close after an additional 30d of inactivity.

If this issue is safe to close now please do so with /close.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/lifecycle rotten
/remove-lifecycle stale

@k8s-ci-robot k8s-ci-robot added lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. and removed lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. labels Mar 28, 2018
@fejta-bot
Copy link

Rotten issues close after 30d of inactivity.
Reopen the issue with /reopen.
Mark the issue as fresh with /remove-lifecycle rotten.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/close

@timthelion
Copy link

I think you're supposed to use the Enum method: https://stackoverflow.com/questions/50464205/how-to-set-a-protobuf2-enum-using-golang

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed.
Projects
None yet
Development

No branches or pull requests

4 participants