Skip to content

Commit

Permalink
Add missing metav1.ObjectMeta to NetworkPolicyEvaluation API type (#6675
Browse files Browse the repository at this point in the history
)

It seems that omitting the field was a mistake when defining the API.
New versions of the K8s code generators (client-gen specifically) will
not work with types missing this field.
See kubernetes/code-generator@688a73a
This is preventing us from updating to a more recent version of the K8s
libraries and of the code generators.

Note that I believe that this API was modeled after the upstream
TokenReview API (which like this one only supports the "create" verb,
and returns a response immediately). The TokenReview type does include a
metav1.ObjectMeta field.

Unfortunately, for backwards-compatibility, we need to use Protobuf
field number 3 for the metadata field, while K8s always uses 1. This is
a bit surprising, but it should only affect the wire format, and nothing
else.

Signed-off-by: Antonin Bas <antonin.bas@broadcom.com>
  • Loading branch information
antoninbas authored Sep 19, 2024
1 parent b180c65 commit cf16884
Show file tree
Hide file tree
Showing 8 changed files with 270 additions and 195 deletions.
1 change: 1 addition & 0 deletions pkg/apis/controlplane/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,7 @@ type NetworkPolicyNodeStatus struct {
// NetworkPolicyEvaluation contains the request and response for a NetworkPolicy evaluation.
type NetworkPolicyEvaluation struct {
metav1.TypeMeta
metav1.ObjectMeta
Request *NetworkPolicyEvaluationRequest
Response *NetworkPolicyEvaluationResponse
}
Expand Down
430 changes: 238 additions & 192 deletions pkg/apis/controlplane/v1beta2/generated.pb.go

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions pkg/apis/controlplane/v1beta2/generated.proto

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 10 additions & 2 deletions pkg/apis/controlplane/v1beta2/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -458,8 +458,16 @@ type NetworkPolicyNodeStatus struct {
// NetworkPolicyEvaluation contains the request and response for a NetworkPolicy evaluation.
type NetworkPolicyEvaluation struct {
metav1.TypeMeta `json:",inline"`
Request *NetworkPolicyEvaluationRequest `json:"request,omitempty" protobuf:"bytes,1,opt,name=request"`
Response *NetworkPolicyEvaluationResponse `json:"response,omitempty" protobuf:"bytes,2,opt,name=response"`
// ObjectMeta was omitted by mistake when this type was first defined, and was added later on.
// To ensure backwards-compatibility, we had to use Protobuf field number 3 when adding the
// field, as 1 was already taken by the request field. This is unusual, as K8s API types
// always use 1 as the Protobuf field number for the metadata field, and that's also what we
// do for all other Antrea API types. It should only affect the wire format, and nothing else.
// When a new version of this API is introduced in the future (e.g., v1), we can correct
// this and assign 1 as the Protobuf field number for the metadata field.
metav1.ObjectMeta `json:"metadata,omitempty" protobuf:"bytes,3,opt,name=metadata"`
Request *NetworkPolicyEvaluationRequest `json:"request,omitempty" protobuf:"bytes,1,opt,name=request"`
Response *NetworkPolicyEvaluationResponse `json:"response,omitempty" protobuf:"bytes,2,opt,name=response"`
}

// Entity contains Namespace and Pod name as a request parameter.
Expand Down
2 changes: 2 additions & 0 deletions pkg/apis/controlplane/v1beta2/zz_generated.conversion.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pkg/apis/controlplane/v1beta2/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pkg/apis/controlplane/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 8 additions & 1 deletion pkg/apiserver/openapi/zz_generated.openapi.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit cf16884

Please sign in to comment.