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

codegen: Fix the hack/update-codegen.sh template #564

Closed
wants to merge 5 commits into from

Conversation

timflannagan
Copy link
Contributor

@timflannagan timflannagan commented Sep 19, 2024

Description

This is a quick follow-up to #560 which updated the generate_script.go for Kubernetes clients.

Why is this needed?

When pulling the most recent of solo-kit into the Gloo repository, the following hack/update-codegen.sh bash script was produced:

#!/usr/bin/env bash

set -o errexit
set -o nounset
set -o pipefail

SCRIPT_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
ROOT_PKG=github.com/solo-io/gloo/projects/gateway/pkg/api/v1
CLIENT_PKG=${ROOT_PKG}/kube/client
APIS_PKG=${ROOT_PKG}/kube/apis

# Grab code-generator version from go.sum.
CODEGEN_PKG=$(go list -f '{{ .Dir }}' -m k8s.io/code-generator)
GENGO_PKG=$(go list -f '{{ .Dir }}' -m k8s.io/gengo/v2)

echo ">> Using ${CODEGEN_PKG}"

# code-generator does work with go.mod but makes assumptions about
# the project living in $GOPATH/src. To work around this and support
# any location; create a temporary directory, use this as an output
# base, and copy everything back once generated.
TEMP_DIR=$(mktemp -d)
cleanup() {
    echo ">> Removing ${TEMP_DIR}"
    rm -rf ${TEMP_DIR}
}
trap "cleanup" EXIT SIGINT

echo ">> Temporary output directory ${TEMP_DIR}"

mkdir -p "${TEMP_DIR}/${ROOT_PKG}/pkg/client/informers" \
         "${TEMP_DIR}/${ROOT_PKG}/pkg/client/listers" \
         "${TEMP_DIR}/${ROOT_PKG}/pkg/client/clientset"

# Ensure we can execute.
chmod +x ${CODEGEN_PKG}/kube_codegen.sh

source ${CODEGEN_PKG}/kube_codegen.sh kube::codegen::gen_client \
    --output-dir "${TEMP_DIR}" \
    --output-pkg "${CLIENT_PKG}" \
    --with-watch \
    --boilerplate "${GENGO_PKG}/boilerplate/boilerplate.go.txt" \
    ${APIS_PKG}

ls -lha $TEMP_DIR

# Copy everything back.
cp -r "${TEMP_DIR}/${ROOT_PKG}/." "${SCRIPT_ROOT}/"

When I try to run that file locally, the following script output is produced:

Note: I manually added a tree command to show the script is a no-op for client generation.

$ bash projects/gateway/pkg/api/v1/kube/hack/update-codegen.sh
>> Using /home/timflannagan/go/pkg/mod/k8s.io/code-generator@v0.31.1
>> Temporary output directory /tmp/tmp.8w2d92aFvh
total 72K
drwx------   3 timflannagan timflannagan 4.0K Sep 19 21:07 .
drwxrwxrwt 299 root         root          60K Sep 19 21:07 ..
drwxrwxr-x   3 timflannagan timflannagan 4.0K Sep 19 21:07 github.com
>> Removing /tmp/tmp.8w2d92aFvh
/tmp/tmp.8w2d92aFvh
└── github.com
    └── solo-io
        └── gloo
            └── projects
                └── gateway
                    └── pkg
                        └── api
                            └── v1
                                └── pkg
                                    └── client
                                        ├── clientset
                                        ├── informers
                                        └── listers

This no-op output is due to a couple of reasons. Let's replace the solo-kit dependency with a local copy to debug this further:

diff --git a/go.mod b/go.mod
index 86b7390f2..76356d141 100644
--- a/go.mod
+++ b/go.mod
@@ -347,6 +347,8 @@ replace (
        // Required for proper serialization of CRDs
        github.com/renstrom/dedent => github.com/lithammer/dedent v1.0.0
 
+       github.com/solo-io/solo-kit => ../solo-kit
+

And then start with the first problem, which is the script attempting to source the kube_codegen.sh script and run a command that's defined within the same script in the same LOC. Let's manually fix that LOC in the script:

diff --git a/projects/gateway/pkg/api/v1/kube/hack/update-codegen.sh b/projects/gateway/pkg/api/v1/kube/hack/update-codegen.sh
index fd16a0d8d..a03262958 100755
--- a/projects/gateway/pkg/api/v1/kube/hack/update-codegen.sh
+++ b/projects/gateway/pkg/api/v1/kube/hack/update-codegen.sh
@@ -23,6 +23,7 @@ echo ">> Using ${CODEGEN_PKG}"
 TEMP_DIR=$(mktemp -d)
 cleanup() {
     echo ">> Removing ${TEMP_DIR}"
+    tree ${TEMP_DIR}
     rm -rf ${TEMP_DIR}
 }
 trap "cleanup" EXIT SIGINT
@@ -35,8 +36,9 @@ mkdir -p "${TEMP_DIR}/${ROOT_PKG}/pkg/client/informers" \
 
 # Ensure we can execute.
 chmod +x ${CODEGEN_PKG}/kube_codegen.sh
+source ${CODEGEN_PKG}/kube_codegen.sh
 
-source ${CODEGEN_PKG}/kube_codegen.sh kube::codegen::gen_client \
+kube::codegen::gen_client \

Which produces a new error that we need to burn down:

$ bash projects/gateway/pkg/api/v1/kube/hack/update-codegen.sh    
>> Using /home/timflannagan/go/pkg/mod/k8s.io/code-generator@v0.31.1
>> Temporary output directory /tmp/tmp.xsmKiVq9QM
go: downloading k8s.io/gengo/v2 v2.0.0-20240228010128-51d4e06bde70
go: downloading golang.org/x/text v0.16.0
go: downloading golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d
go: downloading golang.org/x/sync v0.7.0
go: downloading golang.org/x/mod v0.17.0
grep: github.com/solo-io/gloo/projects/gateway/pkg/api/v1/kube/apis: No such file or directory
total 72K
drwx------   3 timflannagan timflannagan 4.0K Sep 19 21:09 .
drwxrwxrwt 300 root         root          60K Sep 19 21:09 ..
drwxrwxr-x   3 timflannagan timflannagan 4.0K Sep 19 21:09 github.com
>> Removing /tmp/tmp.xsmKiVq9QM
/tmp/tmp.xsmKiVq9QM
└── github.com
    └── solo-io
        └── gloo
            └── projects
                └── gateway
                    └── pkg
                        └── api
                            └── v1
                                └── pkg
                                    └── client
                                        ├── clientset
                                        ├── informers
                                        └── listers

After tinkering with this for a while, I refactored the template script to use the right directories with the gen_client sub-command and new client generated output was being copied back to the project's source. However, this client generation was incomplete, and lister & informer generated files were empty (i.e. no-op operations).

I wasn't able to determine the root cause for why the new gen_client-based approach didn't work, but after researching how repositories in the community were handling k8s 1.31 bumps, I saw a lot of repositories were referencing the gateway-api's implementation that runs k8s.io/code-generator binaries directly.

Refactoring the template to use this new approach fixed the no-op listener and informer issues observed with the singular gen_client command, and we were back in business:

$ bash projects/gateway/pkg/api/v1/kube/hack/update-codegen.sh                        130 ↵
Generating clientset at github.com/solo-io/gloo/projects/gateway/pkg/api/v1/kube/client/clientset
W0919 21:17:06.305133 2801992 parse.go:817] Making unsupported type entry "any" for: &types.Alias{obj:(*types.TypeName)(0x40000a0be0), orig:(*types.Alias)(0x40000441c0), tparams:(*types.TypeParamList)(nil), targs:(*types.TypeList)(nil), fromRHS:(*types.Interface)(0x40000a0b40), actual:(*types.Interface)(0x40000a0b40)}
W0919 21:17:06.305567 2801992 parse.go:817] Making unsupported type entry "reflect.uncommonType" for: &types.Alias{obj:(*types.TypeName)(0x400aac3680), orig:(*types.Alias)(0x400b02f700), tparams:(*types.TypeParamList)(nil), targs:(*types.TypeList)(nil), fromRHS:(*types.Named)(0x40027ef650), actual:(*types.Named)(0x40027ef650)}
W0919 21:17:06.307825 2801992 parse.go:817] Making unsupported type entry "google.golang.org/protobuf/runtime/protoimpl.MessageState" for: &types.Alias{obj:(*types.TypeName)(0x402d5ec910), orig:(*types.Alias)(0x402d5d9b00), tparams:(*types.TypeParamList)(nil), targs:(*types.TypeList)(nil), fromRHS:(*types.Named)(0x4028fc2ee0), actual:(*types.Named)(0x4028fc2ee0)}
W0919 21:17:06.307843 2801992 parse.go:817] Making unsupported type entry "google.golang.org/protobuf/runtime/protoimpl.SizeCache" for: &types.Alias{obj:(*types.TypeName)(0x402d5ec960), orig:(*types.Alias)(0x402d5d9b80), tparams:(*types.TypeParamList)(nil), targs:(*types.TypeList)(nil), fromRHS:(*types.Alias)(0x4028fec080), actual:(*types.Basic)(0x7804e0)}
W0919 21:17:06.307848 2801992 parse.go:817] Making unsupported type entry "google.golang.org/protobuf/runtime/protoimpl.UnknownFields" for: &types.Alias{obj:(*types.TypeName)(0x402d5eca00), orig:(*types.Alias)(0x402d5d9c80), tparams:(*types.TypeParamList)(nil), targs:(*types.TypeList)(nil), fromRHS:(*types.Alias)(0x4028fec100), actual:(*types.Slice)(0x4028b51230)}
W0919 21:17:06.307915 2801992 parse.go:817] Making unsupported type entry "google.golang.org/protobuf/proto.Message" for: &types.Alias{obj:(*types.TypeName)(0x40196fa8c0), orig:(*types.Alias)(0x4019e89c40), tparams:(*types.TypeParamList)(nil), targs:(*types.TypeList)(nil), fromRHS:(*types.Named)(0x400fce83f0), actual:(*types.Named)(0x400fce83f0)}
W0919 21:17:06.308146 2801992 parse.go:817] Making unsupported type entry "google.golang.org/protobuf/reflect/protoreflect.ExtensionDescriptor" for: &types.Alias{obj:(*types.TypeName)(0x4017643400), orig:(*types.Alias)(0x4017647ec0), tparams:(*types.TypeParamList)(nil), targs:(*types.TypeList)(nil), fromRHS:(*types.Named)(0x400fce8cb0), actual:(*types.Named)(0x400fce8cb0)}
W0919 21:17:06.308785 2801992 parse.go:817] Making unsupported type entry "google.golang.org/protobuf/reflect/protoreflect.FieldNumber" for: &types.Alias{obj:(*types.TypeName)(0x4017642b40), orig:(*types.Alias)(0x401765c080), tparams:(*types.TypeParamList)(nil), targs:(*types.TypeList)(nil), fromRHS:(*types.Named)(0x400fce8070), actual:(*types.Named)(0x400fce8070)}
W0919 21:17:06.309378 2801992 parse.go:817] Making unsupported type entry "google.golang.org/protobuf/reflect/protoreflect.methods" for: &types.Alias{obj:(*types.TypeName)(0x4017642500), orig:(*types.Alias)(0x40178c0640), tparams:(*types.TypeParamList)(nil), targs:(*types.TypeList)(nil), fromRHS:(*types.Struct)(0x40178a1a70), actual:(*types.Struct)(0x40178a1a70)}
W0919 21:17:06.311365 2801992 parse.go:817] Making unsupported type entry "github.com/golang/protobuf/ptypes/struct.Struct" for: &types.Alias{obj:(*types.TypeName)(0x402eaeae60), orig:(*types.Alias)(0x402eafc2c0), tparams:(*types.TypeParamList)(nil), targs:(*types.TypeList)(nil), fromRHS:(*types.Named)(0x402d96ad20), actual:(*types.Named)(0x402d96ad20)}
W0919 21:17:06.311516 2801992 parse.go:817] Making unsupported type entry "github.com/golang/protobuf/ptypes/wrappers.BoolValue" for: &types.Alias{obj:(*types.TypeName)(0x402e84c640), orig:(*types.Alias)(0x402e83d4c0), tparams:(*types.TypeParamList)(nil), targs:(*types.TypeList)(nil), fromRHS:(*types.Named)(0x4012b6b6c0), actual:(*types.Named)(0x4012b6b6c0)}
Generating listers at github.com/solo-io/gloo/projects/gateway/pkg/api/v1/kube/client/listers
W0919 21:17:09.509293 2802457 parse.go:817] Making unsupported type entry "any" for: &types.Alias{obj:(*types.TypeName)(0x40000a0be0), orig:(*types.Alias)(0x4000044180), tparams:(*types.TypeParamList)(nil), targs:(*types.TypeList)(nil), fromRHS:(*types.Interface)(0x40000a0b40), actual:(*types.Interface)(0x40000a0b40)}
W0919 21:17:09.509715 2802457 parse.go:817] Making unsupported type entry "reflect.uncommonType" for: &types.Alias{obj:(*types.TypeName)(0x40037dbd10), orig:(*types.Alias)(0x40044cc200), tparams:(*types.TypeParamList)(nil), targs:(*types.TypeList)(nil), fromRHS:(*types.Named)(0x400143aee0), actual:(*types.Named)(0x400143aee0)}
W0919 21:17:09.512040 2802457 parse.go:817] Making unsupported type entry "google.golang.org/protobuf/runtime/protoimpl.MessageState" for: &types.Alias{obj:(*types.TypeName)(0x4024a7e2d0), orig:(*types.Alias)(0x4024a56400), tparams:(*types.TypeParamList)(nil), targs:(*types.TypeList)(nil), fromRHS:(*types.Named)(0x400f157810), actual:(*types.Named)(0x400f157810)}
W0919 21:17:09.512058 2802457 parse.go:817] Making unsupported type entry "google.golang.org/protobuf/runtime/protoimpl.SizeCache" for: &types.Alias{obj:(*types.TypeName)(0x4024a7e320), orig:(*types.Alias)(0x4024a56480), tparams:(*types.TypeParamList)(nil), targs:(*types.TypeList)(nil), fromRHS:(*types.Alias)(0x400d2b5e40), actual:(*types.Basic)(0x6f9840)}
W0919 21:17:09.512063 2802457 parse.go:817] Making unsupported type entry "google.golang.org/protobuf/runtime/protoimpl.UnknownFields" for: &types.Alias{obj:(*types.TypeName)(0x4024a7e3c0), orig:(*types.Alias)(0x4024a56580), tparams:(*types.TypeParamList)(nil), targs:(*types.TypeList)(nil), fromRHS:(*types.Alias)(0x400d31ab40), actual:(*types.Slice)(0x400ebefe20)}
W0919 21:17:09.512137 2802457 parse.go:817] Making unsupported type entry "google.golang.org/protobuf/proto.Message" for: &types.Alias{obj:(*types.TypeName)(0x40158bbb30), orig:(*types.Alias)(0x40158e9500), tparams:(*types.TypeParamList)(nil), targs:(*types.TypeList)(nil), fromRHS:(*types.Named)(0x40114aaa10), actual:(*types.Named)(0x40114aaa10)}
W0919 21:17:09.512397 2802457 parse.go:817] Making unsupported type entry "google.golang.org/protobuf/reflect/protoreflect.ExtensionDescriptor" for: &types.Alias{obj:(*types.TypeName)(0x4008da2140), orig:(*types.Alias)(0x4009f65d00), tparams:(*types.TypeParamList)(nil), targs:(*types.TypeList)(nil), fromRHS:(*types.Named)(0x40114ab2d0), actual:(*types.Named)(0x40114ab2d0)}
W0919 21:17:09.513054 2802457 parse.go:817] Making unsupported type entry "google.golang.org/protobuf/reflect/protoreflect.FieldNumber" for: &types.Alias{obj:(*types.TypeName)(0x40088f57c0), orig:(*types.Alias)(0x4009f65e80), tparams:(*types.TypeParamList)(nil), targs:(*types.TypeList)(nil), fromRHS:(*types.Named)(0x40114aa850), actual:(*types.Named)(0x40114aa850)}
W0919 21:17:09.513666 2802457 parse.go:817] Making unsupported type entry "google.golang.org/protobuf/reflect/protoreflect.methods" for: &types.Alias{obj:(*types.TypeName)(0x40088f5180), orig:(*types.Alias)(0x400a527a80), tparams:(*types.TypeParamList)(nil), targs:(*types.TypeList)(nil), fromRHS:(*types.Struct)(0x4008861aa0), actual:(*types.Struct)(0x4008861aa0)}
W0919 21:17:09.515796 2802457 parse.go:817] Making unsupported type entry "github.com/golang/protobuf/ptypes/struct.Struct" for: &types.Alias{obj:(*types.TypeName)(0x40252d4550), orig:(*types.Alias)(0x40252d2780), tparams:(*types.TypeParamList)(nil), targs:(*types.TypeList)(nil), fromRHS:(*types.Named)(0x400938b1f0), actual:(*types.Named)(0x400938b1f0)}
W0919 21:17:09.515944 2802457 parse.go:817] Making unsupported type entry "github.com/golang/protobuf/ptypes/wrappers.BoolValue" for: &types.Alias{obj:(*types.TypeName)(0x40275b8460), orig:(*types.Alias)(0x40275b6440), tparams:(*types.TypeParamList)(nil), targs:(*types.TypeList)(nil), fromRHS:(*types.Named)(0x402613a0e0), actual:(*types.Named)(0x402613a0e0)}
Generating informers at github.com/solo-io/gloo/projects/gateway/pkg/api/v1/kube/client/informers
W0919 21:17:12.136457 2802851 parse.go:817] Making unsupported type entry "any" for: &types.Alias{obj:(*types.TypeName)(0x400014cb90), orig:(*types.Alias)(0x400012a100), tparams:(*types.TypeParamList)(nil), targs:(*types.TypeList)(nil), fromRHS:(*types.Interface)(0x400014caf0), actual:(*types.Interface)(0x400014caf0)}
W0919 21:17:12.136898 2802851 parse.go:817] Making unsupported type entry "reflect.uncommonType" for: &types.Alias{obj:(*types.TypeName)(0x400c0b6b90), orig:(*types.Alias)(0x400bcf33c0), tparams:(*types.TypeParamList)(nil), targs:(*types.TypeList)(nil), fromRHS:(*types.Named)(0x4001269500), actual:(*types.Named)(0x4001269500)}
W0919 21:17:12.139532 2802851 parse.go:817] Making unsupported type entry "google.golang.org/protobuf/runtime/protoimpl.MessageState" for: &types.Alias{obj:(*types.TypeName)(0x402c173cc0), orig:(*types.Alias)(0x402c17e480), tparams:(*types.TypeParamList)(nil), targs:(*types.TypeList)(nil), fromRHS:(*types.Named)(0x402899ae00), actual:(*types.Named)(0x402899ae00)}
W0919 21:17:12.139568 2802851 parse.go:817] Making unsupported type entry "google.golang.org/protobuf/runtime/protoimpl.SizeCache" for: &types.Alias{obj:(*types.TypeName)(0x402c173d10), orig:(*types.Alias)(0x402c17e500), tparams:(*types.TypeParamList)(nil), targs:(*types.TypeList)(nil), fromRHS:(*types.Alias)(0x4028c302c0), actual:(*types.Basic)(0x7198a0)}
W0919 21:17:12.139575 2802851 parse.go:817] Making unsupported type entry "google.golang.org/protobuf/runtime/protoimpl.UnknownFields" for: &types.Alias{obj:(*types.TypeName)(0x402c173db0), orig:(*types.Alias)(0x402c17e600), tparams:(*types.TypeParamList)(nil), targs:(*types.TypeList)(nil), fromRHS:(*types.Alias)(0x4028c30340), actual:(*types.Slice)(0x4028953020)}
W0919 21:17:12.139661 2802851 parse.go:817] Making unsupported type entry "google.golang.org/protobuf/proto.Message" for: &types.Alias{obj:(*types.TypeName)(0x4013ed28c0), orig:(*types.Alias)(0x4019a3c0c0), tparams:(*types.TypeParamList)(nil), targs:(*types.TypeList)(nil), fromRHS:(*types.Named)(0x4019a42460), actual:(*types.Named)(0x4019a42460)}
W0919 21:17:12.140064 2802851 parse.go:817] Making unsupported type entry "google.golang.org/protobuf/reflect/protoreflect.ExtensionDescriptor" for: &types.Alias{obj:(*types.TypeName)(0x401b0bbc70), orig:(*types.Alias)(0x401b0fe9c0), tparams:(*types.TypeParamList)(nil), targs:(*types.TypeList)(nil), fromRHS:(*types.Named)(0x4019a42d20), actual:(*types.Named)(0x4019a42d20)}
W0919 21:17:12.140931 2802851 parse.go:817] Making unsupported type entry "google.golang.org/protobuf/reflect/protoreflect.FieldNumber" for: &types.Alias{obj:(*types.TypeName)(0x401b0bb3b0), orig:(*types.Alias)(0x401b0feb00), tparams:(*types.TypeParamList)(nil), targs:(*types.TypeList)(nil), fromRHS:(*types.Named)(0x40144dfea0), actual:(*types.Named)(0x40144dfea0)}
W0919 21:17:12.141648 2802851 parse.go:817] Making unsupported type entry "google.golang.org/protobuf/reflect/protoreflect.methods" for: &types.Alias{obj:(*types.TypeName)(0x401b0bad70), orig:(*types.Alias)(0x401b8450c0), tparams:(*types.TypeParamList)(nil), targs:(*types.TypeList)(nil), fromRHS:(*types.Struct)(0x401b83b440), actual:(*types.Struct)(0x401b83b440)}
W0919 21:17:12.143921 2802851 parse.go:817] Making unsupported type entry "github.com/golang/protobuf/ptypes/struct.Struct" for: &types.Alias{obj:(*types.TypeName)(0x402cf9b090), orig:(*types.Alias)(0x402cfae5c0), tparams:(*types.TypeParamList)(nil), targs:(*types.TypeList)(nil), fromRHS:(*types.Named)(0x402899b5e0), actual:(*types.Named)(0x402899b5e0)}
W0919 21:17:12.144080 2802851 parse.go:817] Making unsupported type entry "github.com/golang/protobuf/ptypes/wrappers.BoolValue" for: &types.Alias{obj:(*types.TypeName)(0x402d53eb90), orig:(*types.Alias)(0x402d564740), tparams:(*types.TypeParamList)(nil), targs:(*types.TypeList)(nil), fromRHS:(*types.Named)(0x402ab2ba40), actual:(*types.Named)(0x402ab2ba40)}

And the following diff was produced:

$ gs
On branch chore/k8s-1-31
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
	modified:   go.mod
	modified:   go.sum
	modified:   projects/gateway/pkg/api/v1/kube/client/clientset/versioned/fake/clientset_generated.go
	modified:   projects/gateway/pkg/api/v1/kube/client/clientset/versioned/typed/gateway.solo.io/v1/fake/fake_gateway.go
	modified:   projects/gateway/pkg/api/v1/kube/client/clientset/versioned/typed/gateway.solo.io/v1/fake/fake_httplisteneroption.go
	modified:   projects/gateway/pkg/api/v1/kube/client/clientset/versioned/typed/gateway.solo.io/v1/fake/fake_listeneroption.go
	modified:   projects/gateway/pkg/api/v1/kube/client/clientset/versioned/typed/gateway.solo.io/v1/fake/fake_matchablehttpgateway.go
	modified:   projects/gateway/pkg/api/v1/kube/client/clientset/versioned/typed/gateway.solo.io/v1/fake/fake_matchabletcpgateway.go
	modified:   projects/gateway/pkg/api/v1/kube/client/clientset/versioned/typed/gateway.solo.io/v1/fake/fake_routeoption.go
	modified:   projects/gateway/pkg/api/v1/kube/client/clientset/versioned/typed/gateway.solo.io/v1/fake/fake_routetable.go
	modified:   projects/gateway/pkg/api/v1/kube/client/clientset/versioned/typed/gateway.solo.io/v1/fake/fake_virtualhostoption.go
	modified:   projects/gateway/pkg/api/v1/kube/client/clientset/versioned/typed/gateway.solo.io/v1/fake/fake_virtualservice.go
	modified:   projects/gateway/pkg/api/v1/kube/client/clientset/versioned/typed/gateway.solo.io/v1/gateway.go
	modified:   projects/gateway/pkg/api/v1/kube/client/clientset/versioned/typed/gateway.solo.io/v1/httplisteneroption.go
	modified:   projects/gateway/pkg/api/v1/kube/client/clientset/versioned/typed/gateway.solo.io/v1/listeneroption.go
	modified:   projects/gateway/pkg/api/v1/kube/client/clientset/versioned/typed/gateway.solo.io/v1/matchablehttpgateway.go
	modified:   projects/gateway/pkg/api/v1/kube/client/clientset/versioned/typed/gateway.solo.io/v1/matchabletcpgateway.go
	modified:   projects/gateway/pkg/api/v1/kube/client/clientset/versioned/typed/gateway.solo.io/v1/routeoption.go
	modified:   projects/gateway/pkg/api/v1/kube/client/clientset/versioned/typed/gateway.solo.io/v1/routetable.go
	modified:   projects/gateway/pkg/api/v1/kube/client/clientset/versioned/typed/gateway.solo.io/v1/virtualhostoption.go
	modified:   projects/gateway/pkg/api/v1/kube/client/clientset/versioned/typed/gateway.solo.io/v1/virtualservice.go
	modified:   projects/gateway/pkg/api/v1/kube/client/informers/externalversions/factory.go
	modified:   projects/gateway/pkg/api/v1/kube/client/listers/gateway.solo.io/v1/gateway.go
	modified:   projects/gateway/pkg/api/v1/kube/client/listers/gateway.solo.io/v1/httplisteneroption.go
	modified:   projects/gateway/pkg/api/v1/kube/client/listers/gateway.solo.io/v1/listeneroption.go
	modified:   projects/gateway/pkg/api/v1/kube/client/listers/gateway.solo.io/v1/matchablehttpgateway.go
	modified:   projects/gateway/pkg/api/v1/kube/client/listers/gateway.solo.io/v1/matchabletcpgateway.go
	modified:   projects/gateway/pkg/api/v1/kube/client/listers/gateway.solo.io/v1/routeoption.go
	modified:   projects/gateway/pkg/api/v1/kube/client/listers/gateway.solo.io/v1/routetable.go
	modified:   projects/gateway/pkg/api/v1/kube/client/listers/gateway.solo.io/v1/virtualhostoption.go
	modified:   projects/gateway/pkg/api/v1/kube/client/listers/gateway.solo.io/v1/virtualservice.go
	modified:   projects/gateway/pkg/api/v1/kube/hack/update-codegen.sh

Lastly, we can verify the script works as lister-gen generated lister code that uses the new generic implementation introduced to client-go in 1.31:

@@ -38,25 +38,17 @@ type VirtualServiceLister interface {
 
 // virtualServiceLister implements the VirtualServiceLister interface.
 type virtualServiceLister struct {
-       indexer cache.Indexer
+       listers.ResourceIndexer[*v1.VirtualService]
 }
 
 // NewVirtualServiceLister returns a new VirtualServiceLister.
 func NewVirtualServiceLister(indexer cache.Indexer) VirtualServiceLister {
-       return &virtualServiceLister{indexer: indexer}
-}
-
-// List lists all VirtualServices in the indexer.
-func (s *virtualServiceLister) List(selector labels.Selector) (ret []*v1.VirtualService, err error) {
-       err = cache.ListAll(s.indexer, selector, func(m interface{}) {
-               ret = append(ret, m.(*v1.VirtualService))
-       })
-       return ret, err
+       return &virtualServiceLister{listers.New[*v1.VirtualService](indexer, v1.Resource("virtualservice"))}
 }
 
 // VirtualServices returns an object that can list and get VirtualServices.
 func (s *virtualServiceLister) VirtualServices(namespace string) VirtualServiceNamespaceLister {
-       return virtualServiceNamespaceLister{indexer: s.indexer, namespace: namespace}
+       return virtualServiceNamespaceLister{listers.NewNamespaced[*v1.VirtualService](s.ResourceIndexer, namespace)}
 }
 
 // VirtualServiceNamespaceLister helps list and get VirtualServices.
@@ -74,26 +66,5 @@ type VirtualServiceNamespaceLister interface {
 // virtualServiceNamespaceLister implements the VirtualServiceNamespaceLister
 // interface.
 type virtualServiceNamespaceLister struct {
-       indexer   cache.Indexer
-       namespace string
-}
-
-// List lists all VirtualServices in the indexer for a given namespace.
-func (s virtualServiceNamespaceLister) List(selector labels.Selector) (ret []*v1.VirtualService, err error) {
-       err = cache.ListAllByNamespace(s.indexer, s.namespace, selector, func(m interface{}) {
-               ret = append(ret, m.(*v1.VirtualService))
-       })
-       return ret, err
-}
-
-// Get retrieves the VirtualService from the indexer for a given namespace and name.
-func (s virtualServiceNamespaceLister) Get(name string) (*v1.VirtualService, error) {
-       obj, exists, err := s.indexer.GetByKey(s.namespace + "/" + name)
-       if err != nil {
-               return nil, err
-       }
-       if !exists {
-               return nil, errors.NewNotFound(v1.Resource("virtualservice"), name)
-       }
-       return obj.(*v1.VirtualService), nil
+       listers.ResourceIndexer[*v1.VirtualService]

Signed-off-by: timflannagan <timflannagan@gmail.com>
@solo-changelog-bot
Copy link

Issues linked to changelog:
solo-io/gloo#9683

Signed-off-by: timflannagan <timflannagan@gmail.com>
Makefile Outdated
if [ "$(shell uname)" == "Darwin" ]; then \
if [ "$(shell uname)" = "Darwin" ]; then \
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Needed to get install-protoc working on a fresh fork.

@timflannagan
Copy link
Contributor Author

Hmm I tried running make test locally and it immediately failed as the solo.io/v1 k8s clients are broken. I looked into migrating those to the right directory structure and updating the clients/informers/listers, but that appears to break some custom client code that we introduced to a fork many, many years ago:

diff --git a/pkg/api/v1/clients/kube/client/clientset/versioned/fake/clientset_generated.go b/pkg/api/v1/clients/kube/client/clientset/versioned/fake/clientset_generated.go
index e162c4a..b4c2d23 100644
--- a/pkg/api/v1/clients/kube/client/clientset/versioned/fake/clientset_generated.go
+++ b/pkg/api/v1/clients/kube/client/clientset/versioned/fake/clientset_generated.go
@@ -19,9 +19,7 @@ limitations under the License.
 package fake
 
 import (
-       "github.com/solo-io/solo-kit/pkg/api/v1/clients/kube/crd"
        clientset "github.com/solo-io/solo-kit/pkg/api/v1/clients/kube/client/clientset/versioned"
-       realregisterfile "github.com/solo-io/solo-kit/pkg/api/v1/clients/kube/client/clientset/versioned/scheme"
        resourcesv1 "github.com/solo-io/solo-kit/pkg/api/v1/clients/kube/client/clientset/versioned/typed/solo.io/v1"
        fakeresourcesv1 "github.com/solo-io/solo-kit/pkg/api/v1/clients/kube/client/clientset/versioned/typed/solo.io/v1/fake"
        "k8s.io/apimachinery/pkg/runtime"
@@ -33,23 +31,14 @@ import (
 
 // NewSimpleClientset returns a clientset that will respond with the provided objects.
 // It's backed by a very simple object tracker that processes creates, updates and deletions as-is,
-// without applying any validations and/or defaults. It shouldn't be considered a replacement
+// without applying any field management, validations and/or defaults. It shouldn't be considered a replacement
 // for a real clientset and is mostly useful in simple unit tests.
-func NewSimpleClientset(crd crd.Crd, objects ...runtime.Object) *Clientset { // NOTE(marco): this line was updated
-
-       // ###############################################################################################
-       // ###############################################################################################
-       // NOTE(marco): the following line was updated to reference the scheme our CRD objects register
-       // with. Originally, this pointed to the scheme in the register.go file in the same package.
-       //
-       // The generated code expected pkg/api/v1/clients/kube/crd/solo.io/v1 to export a function named
-       // "AddToScheme" that would be called from both fake/register.go and scheme/register.go to add
-       // the custom types to the respective schemes. We moved the same logic to the "NewCrd" function
-       // in pkg/api/v1/clients/kube/crd/crd.go, but it always writes to the scheme in scheme/register.go,
-       // so we reference it here.
-       // ###############################################################################################
-       // ###############################################################################################
-       o := testing.NewObjectTracker(realregisterfile.Scheme, codecs.UniversalDecoder())
+//
+// DEPRECATED: NewClientset replaces this with support for field management, which significantly improves
+// server side apply testing. NewClientset is only available when apply configurations are generated (e.g.
+// via --with-applyconfig).
+func NewSimpleClientset(objects ...runtime.Object) *Clientset {

It seems like we're in a really awkward situation with some cruft with this repository right now.

@timflannagan
Copy link
Contributor Author

Created a tracking issue for this. Closing as I don't have the capacity to push this through right now.

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.

2 participants