Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 

README.md

Slim Kubernetes structures

This package is intended to be a slim copy of the structures used in k8s watchers.

The most common structures are under vendor/k8s.io/api/core/v1/types.go, or vendor/k8s.io/apimachinery/pkg/apis/meta/v1/types.go.

Use the following script to update the slim files. Update the tag variable as necessary. Keep in mind that updating the slim files is not as simple as accepting the changes that the script generates. Only the changes relevant to the structures used by Cilium are necessary to keep.

Note: if updating from RC versions, first run the script as-is and commit in a temporary commit all of the changes generated by the script. Then, update the tag and re-run the script. Any changes to the slim structures in the generated diff is what needs to be committed; all other changes are unnecessary.

tag=v1.35.0
url="https://raw.githubusercontent.com/kubernetes/kubernetes/${tag}"

curl "${url}/staging/src/k8s.io/api/core/v1/doc.go" > pkg/k8s/slim/k8s/api/core/v1/doc.go
curl "${url}/staging/src/k8s.io/api/core/v1/register.go" > pkg/k8s/slim/k8s/api/core/v1/register.go
curl "${url}/staging/src/k8s.io/api/core/v1/taint.go" > pkg/k8s/slim/k8s/api/core/v1/taint.go
curl "${url}/staging/src/k8s.io/api/core/v1/types.go" > pkg/k8s/slim/k8s/api/core/v1/types.go

curl "${url}/staging/src/k8s.io/api/discovery/v1/doc.go" > pkg/k8s/slim/k8s/api/discovery/v1/doc.go
curl "${url}/staging/src/k8s.io/api/discovery/v1/register.go" > pkg/k8s/slim/k8s/api/discovery/v1/register.go
curl "${url}/staging/src/k8s.io/api/discovery/v1/types.go" > pkg/k8s/slim/k8s/api/discovery/v1/types.go
curl "${url}/staging/src/k8s.io/api/discovery/v1/well_known_labels.go" > pkg/k8s/slim/k8s/api/discovery/v1/well_known_labels.go

curl "${url}/staging/src/k8s.io/apimachinery/pkg/labels/doc.go" > pkg/k8s/slim/k8s/apis/labels/doc.go
curl "${url}/staging/src/k8s.io/apimachinery/pkg/labels/labels.go" > pkg/k8s/slim/k8s/apis/labels/labels.go
curl "${url}/staging/src/k8s.io/apimachinery/pkg/labels/selector.go" > pkg/k8s/slim/k8s/apis/labels/selector.go

curl "${url}/staging/src/k8s.io/apimachinery/pkg/apis/meta/v1/validation/validation.go" > pkg/k8s/slim/k8s/apis/meta/v1/validation/validation.go

curl "${url}/staging/src/k8s.io/apimachinery/pkg/apis/meta/v1/doc.go" > pkg/k8s/slim/k8s/apis/meta/v1/doc.go
curl "${url}/staging/src/k8s.io/apimachinery/pkg/apis/meta/v1/helpers.go" > pkg/k8s/slim/k8s/apis/meta/v1/helpers.go
curl "${url}/staging/src/k8s.io/apimachinery/pkg/apis/meta/v1/meta.go" > pkg/k8s/slim/k8s/apis/meta/v1/meta.go
curl "${url}/staging/src/k8s.io/apimachinery/pkg/apis/meta/v1/register.go" > pkg/k8s/slim/k8s/apis/meta/v1/register.go
curl "${url}/staging/src/k8s.io/apimachinery/pkg/apis/meta/v1/time.go" > pkg/k8s/slim/k8s/apis/meta/v1/time.go
curl "${url}/staging/src/k8s.io/apimachinery/pkg/apis/meta/v1/time_proto.go" > pkg/k8s/slim/k8s/apis/meta/v1/time_proto.go
curl "${url}/staging/src/k8s.io/apimachinery/pkg/apis/meta/v1/types.go" > pkg/k8s/slim/k8s/apis/meta/v1/types.go

curl "${url}/staging/src/k8s.io/apimachinery/pkg/apis/meta/v1beta1/doc.go" > pkg/k8s/slim/k8s/apis/meta/v1beta1/doc.go
curl "${url}/staging/src/k8s.io/apimachinery/pkg/apis/meta/v1beta1/register.go" > pkg/k8s/slim/k8s/apis/meta/v1beta1/register.go
curl "${url}/staging/src/k8s.io/apimachinery/pkg/apis/meta/v1beta1/types.go" > pkg/k8s/slim/k8s/apis/meta/v1beta1/types.go

curl "${url}/staging/src/k8s.io/api/networking/v1/doc.go" > pkg/k8s/slim/k8s/api/networking/v1/doc.go
curl "${url}/staging/src/k8s.io/api/networking/v1/register.go" > pkg/k8s/slim/k8s/api/networking/v1/register.go
curl "${url}/staging/src/k8s.io/api/networking/v1/types.go" > pkg/k8s/slim/k8s/api/networking/v1/types.go
curl "${url}/staging/src/k8s.io/api/networking/v1/well_known_annotations.go" > pkg/k8s/slim/k8s/api/networking/v1/well_known_annotations.go

curl "${url}/staging/src/k8s.io/apimachinery/pkg/selection/operator.go" > pkg/k8s/slim/k8s/apis/selection/operator.go

curl "${url}/staging/src/k8s.io/apimachinery/pkg/util/intstr/intstr.go" > pkg/k8s/slim/k8s/apis/util/intstr/intstr.go

curl "${url}/staging/src/k8s.io/apimachinery/pkg/api/meta/conditions.go" > pkg/k8s/slim/k8s/apis/api/meta/conditions.go

All fields of the copied structures are exactly the same as the ones available in the official k8s source code. To keep a slimmer version of these structures make sure the unused fields by Cilium are removed from the slimmer versions. See below section regarding gotchas.

If new fields need to be added or removed to these structures, some files need to be regenerated with make generate-k8s-api in the root directory of this repository.

The directory ./k8s/client is entirely auto-generated. This directory has the source code of an optimized Kubernetes client.

With this optimized Kubernetes client we can wrap some official and non-optimized Kubernetes interfaces with the ones built for the slimmer versions. So make sure you are correctly wrapping the interfaces with our implementations. If this client is used a structure that is not registered under "register.go" of that package or if the client is being used for a type that is not optimized yet, you will hit the error: Failed to list ... no kind "..." is registered for version "v1". To fix this make sure the package is registered and the client is supposed to be used for that structure.

Gotchas for updating slim structures

  • Remove any changes regarding comments starting with "import ..." because that affects the protoc's code generation
  • Remove any changes regarding a change of the import path for the core and meta v1* packages, i.e. undo changes that cause the import path to fallback to "k8s.io/..." rather than "pkg/k8s/slim/..."
  • Remove all new structures that are not used by Cilium and only update the structures that are in use
  • Ignore all changes to pkg/k8s/slim/k8s/apis/meta/v1/meta.go regarding the Object interface methods, unless the updating you are performing requires these interface methods to change.
  • Ignore changes that remove that the kubebuilder directives on the LabelSelectorRequirement struct, especially for the Operator field.
  • Ignore changes to LabelSelector inside pkg/k8s/slim/k8s/apis/meta/v1/types.go and MatchLabelsValue. The latter is a custom type that we depend on.
  • Ignore changes inside pkg/k8s/slim/k8s/apis/labels/selector.go regarding new fields in the Parser struct, especially with path. If new fields are added to the struct, add them if you know what you are doing.