Files
Aleksei Sviridkin 3dde6503ec refactor(api): keep each app's kind without the apimachinery fork
Every apps kind is registered on the one Application Go type, and the
stock Scheme.ConvertToVersion picks the first kind registered for a
type, so without help a Redis comes back from the API as whichever app
kind was registered first. So far the fix lived in a fork of
k8s.io/apimachinery that patches ConvertToVersion. Upstream has not
taken the change, and the fork has to be rebased onto every Kubernetes
minor before the libraries can move.

The apps group now encodes through a serializer that picks the kind the
object carries, along the lines upstream suggested instead of changing
Scheme. The replace directive goes, and with it the Renovate rule that
kept the fork's stale release tags from being proposed as updates. The
serializer relies on the storage stamping the kind on every object it
returns, which it does. A test drives create, get, list, update, watch,
apply and table through the real handler chain for two kinds and fails
without the serializer on upstream apimachinery.

One path converts through the Scheme rather than the serializer and
goes back to the first registered kind: the row objects of a Table
requested with includeObject=Object, which kubectl asks for only with
--sort-by. Admission webhooks and ValidatingAdmissionPolicy get the
request kind set explicitly.

Assisted-by: LLM
Signed-off-by: Aleksei Sviridkin <f@lex.la>
2026-09-26 16:08:24 +03:00

105 lines
3.3 KiB
Go

// SPDX-License-Identifier: Apache-2.0
// Copyright 2026 The Cozystack Authors.
package securitygroupcontroller
import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
)
// CiliumNetworkPolicy is a metadata-only, in-tree mirror of the cilium.io/v2
// CiliumNetworkPolicy resource. The securitygroup-controller only reads a
// policy's marker label, its attachments annotation and its finalizers — never
// the spec — so this mirror deliberately omits the spec entirely, keeping the
// controller binary free of the full Cilium module. Importing it would tie this
// project's k8s.io libraries to Cilium's: Go builds with the higher of the two
// required versions, so a Cilium release built on a newer Kubernetes would drag
// them forward, and one built on an older Kubernetes would have to compile
// against ours.
//
// NEVER Update an object of this type: a PUT would serialize it without a spec
// and wipe the real policy's rules. Finalizer changes go through MergeFrom
// patches, which carry only the changed fields.
type CiliumNetworkPolicy struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
}
// CiliumNetworkPolicyList is a list of CiliumNetworkPolicy objects.
type CiliumNetworkPolicyList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []CiliumNetworkPolicy `json:"items"`
}
var ciliumGroupVersion = schema.GroupVersion{Group: "cilium.io", Version: "v2"}
// AddToScheme registers the in-tree CiliumNetworkPolicy mirror so the
// controller-runtime client can list and patch the backing policies.
func AddToScheme(scheme *runtime.Scheme) error {
scheme.AddKnownTypes(ciliumGroupVersion,
&CiliumNetworkPolicy{},
&CiliumNetworkPolicyList{},
)
metav1.AddToGroupVersion(scheme, ciliumGroupVersion)
return nil
}
// DeepCopyInto copies the receiver into out.
func (in *CiliumNetworkPolicy) DeepCopyInto(out *CiliumNetworkPolicy) {
*out = *in
out.TypeMeta = in.TypeMeta
in.ObjectMeta.DeepCopyInto(&out.ObjectMeta)
}
// DeepCopy returns a deep copy of the receiver.
func (in *CiliumNetworkPolicy) DeepCopy() *CiliumNetworkPolicy {
if in == nil {
return nil
}
out := new(CiliumNetworkPolicy)
in.DeepCopyInto(out)
return out
}
// DeepCopyObject returns a deep copy of the receiver as a runtime.Object.
func (in *CiliumNetworkPolicy) DeepCopyObject() runtime.Object {
if c := in.DeepCopy(); c != nil {
return c
}
return nil
}
// DeepCopyInto copies the receiver into out.
func (in *CiliumNetworkPolicyList) DeepCopyInto(out *CiliumNetworkPolicyList) {
*out = *in
out.TypeMeta = in.TypeMeta
in.ListMeta.DeepCopyInto(&out.ListMeta)
if in.Items != nil {
out.Items = make([]CiliumNetworkPolicy, len(in.Items))
for i := range in.Items {
in.Items[i].DeepCopyInto(&out.Items[i])
}
}
}
// DeepCopy returns a deep copy of the receiver.
func (in *CiliumNetworkPolicyList) DeepCopy() *CiliumNetworkPolicyList {
if in == nil {
return nil
}
out := new(CiliumNetworkPolicyList)
in.DeepCopyInto(out)
return out
}
// DeepCopyObject returns a deep copy of the receiver as a runtime.Object.
func (in *CiliumNetworkPolicyList) DeepCopyObject() runtime.Object {
if c := in.DeepCopy(); c != nil {
return c
}
return nil
}