Skip to content

Commit c165a09

Browse files
authored
Upgrade Nephio to Go 1.22 (#597)
**What type of PR is this?** > Uncomment only one /kind <> line, hit enter to put that in a new line, and remove leading whitespaces from that line: > /kind bug /kind cleanup > /kind design > /kind documentation > /kind failing-test > /kind feature > /kind flake **What this PR does / why we need it:** - Updated go version in go.mod files - Updated go version in github workflows - Updated base image to 1.22.2-bookworm in Dockerfiles - Updated Go/Golang-CI/GoSec versions in makefiles - Updated reflect.TypeOf() to reflect.TypeFor[]() where relevant **Which issue(s) this PR fixes:** Fixes [Issue 510](#510). **Special notes for your reviewer:** **Does this PR introduce a user-facing change?:** no
1 parent 1517562 commit c165a09

File tree

39 files changed

+56
-53
lines changed

39 files changed

+56
-53
lines changed

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
.SHELLFLAGS = -ec
1616

17-
GO_VERSION ?= 1.20.2
17+
GO_VERSION ?= 1.22.2
1818
IMG_REGISTRY ?= docker.io/nephio
1919

2020
# find all subdirectories with a go.mod file in them

controllers/pkg/cluster/capi/capi.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ func (r *Capi) isCapiClusterReady(ctx context.Context) bool {
6161
r.l = log.FromContext(ctx)
6262
name := r.GetClusterName()
6363

64-
cl := resource.GetUnstructuredFromGVK(&schema.GroupVersionKind{Group: capiv1beta1.GroupVersion.Group, Version: capiv1beta1.GroupVersion.Version, Kind: reflect.TypeOf(capiv1beta1.Cluster{}).Name()})
64+
cl := resource.GetUnstructuredFromGVK(&schema.GroupVersionKind{Group: capiv1beta1.GroupVersion.Group, Version: capiv1beta1.GroupVersion.Version, Kind: reflect.TypeFor[capiv1beta1.Cluster]().Name()})
6565
if err := r.Get(ctx, types.NamespacedName{Namespace: r.Secret.GetNamespace(), Name: name}, cl); err != nil {
6666
r.l.Error(err, "cannot get cluster")
6767
return false

controllers/pkg/go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module github.com/nephio-project/nephio/controllers/pkg
22

3-
go 1.20
3+
go 1.22
44

55
replace (
66
github.com/GoogleContainerTools/kpt/porch => github.com/GoogleContainerTools/kpt/porch v0.0.0-20230526213300-77a54e3b8e88

controllers/pkg/porch/util/packagevariant_test.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,15 @@ package util
1818

1919
import (
2020
"context"
21+
"reflect"
22+
"testing"
23+
2124
porchapi "github.com/GoogleContainerTools/kpt/porch/api/porch/v1alpha1"
2225
pvapi "github.com/GoogleContainerTools/kpt/porch/controllers/packagevariants/api/v1alpha1"
2326
"github.com/stretchr/testify/require"
2427
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
25-
"reflect"
2628
"sigs.k8s.io/controller-runtime/pkg/client"
2729
"sigs.k8s.io/yaml"
28-
"testing"
2930
)
3031

3132
type fakeClient struct {
@@ -67,7 +68,7 @@ func TestPackageRevisionIsReady(t *testing.T) {
6768
{
6869
APIVersion: "config.porch.kpt.dev/v1alpha1",
6970
Controller: &tr,
70-
Kind: reflect.TypeOf(pvapi.PackageVariant{}).Name(),
71+
Kind: reflect.TypeFor[pvapi.PackageVariant]().Name(),
7172
Name: "wc-argocd-argocd-cluster",
7273
},
7374
},

controllers/pkg/reconcilers/token/reconciler.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ func (r *reconciler) createToken(ctx context.Context, giteaClient giteaclient.Gi
185185
secret := &corev1.Secret{
186186
TypeMeta: metav1.TypeMeta{
187187
APIVersion: corev1.SchemeGroupVersion.Identifier(),
188-
Kind: reflect.TypeOf(corev1.Secret{}).Name(),
188+
Kind: reflect.TypeFor[corev1.Secret]().Name(),
189189
},
190190
ObjectMeta: metav1.ObjectMeta{
191191
Namespace: cr.GetNamespace(),

default-go-test.mk

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
# limitations under the License.
1414

1515

16-
GO_VERSION ?= 1.20.2
16+
GO_VERSION ?= 1.22.2
1717
TEST_COVERAGE_FILE=lcov.info
1818
TEST_COVERAGE_HTML_FILE=coverage_unit.html
1919
TEST_COVERAGE_FUNC_FILE=func_coverage.out
@@ -28,7 +28,7 @@ unit: test
2828
.PHONY: test
2929
test: ## Run unit tests (go test)
3030
ifeq ($(CONTAINER_RUNNABLE), 0)
31-
$(RUN_CONTAINER_COMMAND) docker.io/library/golang:${GO_VERSION}-alpine3.17 \
31+
$(RUN_CONTAINER_COMMAND) docker.io/library/golang:${GO_VERSION}-alpine3.19 \
3232
sh -e -c "go test ./... -v -coverprofile ${TEST_COVERAGE_FILE}; \
3333
go tool cover -html=${TEST_COVERAGE_FILE} -o ${TEST_COVERAGE_HTML_FILE}; \
3434
go tool cover -func=${TEST_COVERAGE_FILE} -o ${TEST_COVERAGE_FUNC_FILE}"

krm-functions/configinject-fn/Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
FROM golang:1.20-alpine
15+
FROM golang:1.22-alpine
1616
ENV CGO_ENABLED=0
1717
WORKDIR /go/src/
1818
COPY krm-functions/ krm-functions/

krm-functions/configinject-fn/fn/function.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ func New(c client.Client) *FnR {
6363
Owns: map[corev1.ObjectReference]condkptsdk.ResourceKind{
6464
{
6565
APIVersion: nephiorefv1alpha1.GroupVersion.Identifier(),
66-
Kind: reflect.TypeOf(nephiorefv1alpha1.Config{}).Name(),
66+
Kind: reflect.TypeFor[nephiorefv1alpha1.Config]().Name(),
6767
}: condkptsdk.ChildLocal,
6868
},
6969
Watch: map[corev1.ObjectReference]condkptsdk.WatchCallbackFn{

krm-functions/configinject-fn/go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module github.com/nephio-project/nephio/krm-functions/configinject-fn
22

3-
go 1.20
3+
go 1.22
44

55
replace github.com/nephio-project/nephio/krm-functions/lib => ../lib
66

krm-functions/dnn-fn/Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
FROM golang:1.20-alpine
15+
FROM golang:1.22-alpine
1616
ENV CGO_ENABLED=0
1717
WORKDIR /go/src/
1818
COPY krm-functions/ krm-functions/

krm-functions/dnn-fn/fn/function.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ func Run(rl *fn.ResourceList) (bool, error) {
6969
Watch: map[corev1.ObjectReference]condkptsdk.WatchCallbackFn{
7070
{
7171
APIVersion: infrav1alpha1.GroupVersion.Identifier(),
72-
Kind: reflect.TypeOf(infrav1alpha1.WorkloadCluster{}).Name(),
72+
Kind: reflect.TypeFor[infrav1alpha1.WorkloadCluster]().Name(),
7373
}: myFn.WorkloadClusterCallbackFn,
7474
},
7575
PopulateOwnResourcesFn: myFn.desiredOwnedResourceList,

krm-functions/dnn-fn/go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module github.com/nephio-project/nephio/krm-functions/dnn-fn
22

3-
go 1.20
3+
go 1.22
44

55
replace github.com/nephio-project/nephio/krm-functions/lib => ../lib
66

krm-functions/gen-configmap-fn/Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
FROM golang:1.20-alpine
15+
FROM golang:1.22-alpine
1616
ENV CGO_ENABLED=0
1717
WORKDIR /go/src/
1818
COPY krm-functions/ krm-functions/

krm-functions/gen-configmap-fn/go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module github.com/nephio-project/nephio/krm-functions/gen-configmap-fn
22

3-
go 1.20
3+
go 1.22
44

55
replace github.com/nephio-project/nephio/krm-functions/lib => ../lib
66

krm-functions/interface-fn/Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
FROM golang:1.20-alpine
15+
FROM golang:1.22-alpine
1616
ENV CGO_ENABLED=0
1717
WORKDIR /go/src/
1818
COPY krm-functions/ krm-functions/

krm-functions/interface-fn/fn/function.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ func Run(rl *fn.ResourceList) (bool, error) {
5656
Owns: map[corev1.ObjectReference]condkptsdk.ResourceKind{
5757
{
5858
APIVersion: nadv1.SchemeGroupVersion.Identifier(),
59-
Kind: reflect.TypeOf(nadv1.NetworkAttachmentDefinition{}).Name(),
59+
Kind: reflect.TypeFor[nadv1.NetworkAttachmentDefinition]().Name(),
6060
}: condkptsdk.ChildRemoteCondition,
6161
{
6262
APIVersion: ipamv1alpha1.GroupVersion.Identifier(),
@@ -70,7 +70,7 @@ func Run(rl *fn.ResourceList) (bool, error) {
7070
Watch: map[corev1.ObjectReference]condkptsdk.WatchCallbackFn{
7171
{
7272
APIVersion: infrav1alpha1.GroupVersion.Identifier(),
73-
Kind: reflect.TypeOf(infrav1alpha1.WorkloadCluster{}).Name(),
73+
Kind: reflect.TypeFor[infrav1alpha1.WorkloadCluster]().Name(),
7474
}: myFn.WorkloadClusterCallbackFn,
7575
},
7676
PopulateOwnResourcesFn: myFn.desiredOwnedResourceList,
@@ -289,7 +289,7 @@ func BuildNetworkAttachmentDefinition(meta metav1.ObjectMeta, spec nadv1.Network
289289
return &nadv1.NetworkAttachmentDefinition{
290290
TypeMeta: metav1.TypeMeta{
291291
APIVersion: nadv1.SchemeGroupVersion.Identifier(),
292-
Kind: reflect.TypeOf(nadv1.NetworkAttachmentDefinition{}).Name(),
292+
Kind: reflect.TypeFor[nadv1.NetworkAttachmentDefinition]().Name(),
293293
},
294294
ObjectMeta: meta,
295295
Spec: spec,

krm-functions/interface-fn/go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module github.com/nephio-project/nephio/krm-functions/interface-fn
22

3-
go 1.20
3+
go 1.22
44

55
replace github.com/nephio-project/nephio/krm-functions/lib => ../lib
66

krm-functions/ipam-fn/Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
FROM golang:1.20-alpine
15+
FROM golang:1.22-alpine
1616
ENV CGO_ENABLED=0
1717
WORKDIR /go/src/
1818
COPY krm-functions/ krm-functions/

krm-functions/ipam-fn/go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module github.com/nephio-project/nephio/krm-functions/ipam-fn
22

3-
go 1.20
3+
go 1.22
44

55
replace github.com/nephio-project/nephio/krm-functions/lib => ../lib
66

krm-functions/lib/condkptsdk/sdk_stage1_update_children.go

+3
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ func (r *sdk) updateChildren() {
133133
for _, obj := range diff.createObjs {
134134
if r.debug {
135135
fn.Logf("stage1: diff action -> create obj: ref: %s, ownkind: %s\n", kptfilelibv1.GetConditionType(&obj.ref), obj.ownKind)
136+
// #nosec G601
136137
}
137138
status := kptv1.ConditionFalse
138139
if obj.ownKind == ChildLocal {
@@ -151,6 +152,7 @@ func (r *sdk) updateChildren() {
151152
for _, obj := range diff.updateObjs {
152153
if r.debug {
153154
fn.Logf("stage1: diff action -> update obj: %s\n", kptfilelibv1.GetConditionType(&obj.ref))
155+
// #nosec G601
154156
}
155157
if err := r.upsertChildObject(ownGVKKind, []corev1.ObjectReference{forRef, obj.ref}, obj, nil, "update resource", kptv1.ConditionFalse, false); err != nil {
156158
// the errors are already logged, we set the result in the for condition
@@ -163,6 +165,7 @@ func (r *sdk) updateChildren() {
163165
for _, obj := range diff.deleteObjs {
164166
if r.debug {
165167
fn.Logf("stage1: diff action -> delete obj: %s\n", kptfilelibv1.GetConditionType(&obj.ref))
168+
// #nosec G601
166169
}
167170
if err := r.deleteChildObject(ownGVKKind, []corev1.ObjectReference{forRef, obj.ref}, obj, "delete resource"); err != nil {
168171
// the errors are already logged, we set the result in the for condition

krm-functions/lib/go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module github.com/nephio-project/nephio/krm-functions/lib
22

3-
go 1.20
3+
go 1.22
44

55
require (
66
github.com/GoogleContainerTools/kpt v1.0.0-beta.29.0.20230327202912-01513604feaa

krm-functions/lib/kubeobject/kubeobject.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,7 @@ func (o *KubeObjectExt[T1]) getFieldOrPanic(value *T1, fieldName string) interfa
158158
}
159159

160160
func validateTypeOrPanic[T1 any]() {
161-
var x T1
162-
v := reflect.TypeOf(x)
161+
v := reflect.TypeFor[T1]()
163162
if v.Kind() != reflect.Struct {
164163
panic(fmt.Sprintf("type %q is not a struct", v.Name()))
165164
}

krm-functions/lib/kubeobject/lists.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,7 @@ func GetSingleton[T any, PT PtrIsRuntimeObject[T]](objs fn.KubeObjects) (*T, err
8383
return nil, err
8484
}
8585
if len(typedObjs) != 1 {
86-
var x T
87-
return nil, fmt.Errorf("expected exactly 1 instance of %v in the kpt package, but got %v", reflect.TypeOf(x).Name(), len(typedObjs))
86+
return nil, fmt.Errorf("expected exactly 1 instance of %v in the kpt package, but got %v", reflect.TypeFor[T]().Name(), len(typedObjs))
8887
}
8988
return typedObjs[0], nil
9089
}

krm-functions/lib/nad/v1/nad_test.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,15 @@ limitations under the License.
1717
package v1
1818

1919
import (
20+
"reflect"
21+
"testing"
22+
2023
"github.com/GoogleContainerTools/kpt-functions-sdk/go/fn"
2124
"github.com/google/go-cmp/cmp"
2225
nadv1 "github.com/k8snetworkplumbingwg/network-attachment-definition-client/pkg/apis/k8s.cni.cncf.io/v1"
2326
"github.com/stretchr/testify/assert"
2427
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
25-
"reflect"
2628
"sigs.k8s.io/yaml"
27-
"testing"
2829
)
2930

3031
var nadTestSriov = `apiVersion: "k8s.cni.cncf.io/v1"
@@ -105,7 +106,7 @@ func TestNewFromGoStruct(t *testing.T) {
105106
input: &nadv1.NetworkAttachmentDefinition{
106107
TypeMeta: metav1.TypeMeta{
107108
APIVersion: nadv1.SchemeGroupVersion.Identifier(),
108-
Kind: reflect.TypeOf(nadv1.NetworkAttachmentDefinition{}).Name(),
109+
Kind: reflect.TypeFor[nadv1.NetworkAttachmentDefinition]().Name(),
109110
},
110111
ObjectMeta: metav1.ObjectMeta{
111112
Name: "a",

krm-functions/nad-fn/Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
FROM golang:1.20-alpine
15+
FROM golang:1.22-alpine
1616
ENV CGO_ENABLED=0
1717
WORKDIR /go/src/
1818
COPY krm-functions/ krm-functions/

krm-functions/nad-fn/fn/function.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ func Run(rl *fn.ResourceList) (bool, error) {
5555
&condkptsdk.Config{
5656
For: corev1.ObjectReference{
5757
APIVersion: nadv1.SchemeGroupVersion.Identifier(),
58-
Kind: reflect.TypeOf(nadv1.NetworkAttachmentDefinition{}).Name(),
58+
Kind: reflect.TypeFor[nadv1.NetworkAttachmentDefinition]().Name(),
5959
},
6060
Watch: map[corev1.ObjectReference]condkptsdk.WatchCallbackFn{
6161
{
@@ -168,7 +168,7 @@ func (f *nadFn) updateResourceFn(_ *fn.KubeObject, objs fn.KubeObjects) (fn.Kube
168168
nad, err := nadlibv1.NewFromGoStruct(&nadv1.NetworkAttachmentDefinition{
169169
TypeMeta: metav1.TypeMeta{
170170
APIVersion: nadv1.SchemeGroupVersion.Identifier(),
171-
Kind: reflect.TypeOf(nadv1.NetworkAttachmentDefinition{}).Name(),
171+
Kind: reflect.TypeFor[nadv1.NetworkAttachmentDefinition]().Name(),
172172
},
173173
ObjectMeta: metav1.ObjectMeta{Name: fmt.Sprintf("%s-%s", f.forName, interfaceObjs[0].GetName()), Namespace: f.forNamespace},
174174
})

krm-functions/nad-fn/go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module github.com/nephio-project/nephio/krm-functions/nad-fn
22

3-
go 1.20
3+
go 1.22
44

55
replace github.com/nephio-project/nephio/krm-functions/lib => ../lib
66

krm-functions/nfdeploy-fn/Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
FROM golang:1.20-alpine
15+
FROM golang:1.22-alpine
1616
ENV CGO_ENABLED=0
1717
WORKDIR /go/src/
1818
COPY krm-functions/ krm-functions/

krm-functions/nfdeploy-fn/fn/function.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ func Run(rl *fn.ResourceList) (bool, error) {
7474
Watch: map[corev1.ObjectReference]condkptsdk.WatchCallbackFn{
7575
{
7676
APIVersion: infrav1alpha1.GroupVersion.Identifier(),
77-
Kind: reflect.TypeOf(infrav1alpha1.WorkloadCluster{}).Name(),
77+
Kind: reflect.TypeFor[infrav1alpha1.WorkloadCluster]().Name(),
7878
}: nfDeployFn.WorkloadClusterCallbackFn,
7979
},
8080
PopulateOwnResourcesFn: nfDeployFn.desiredOwnedResourceList,

krm-functions/nfdeploy-fn/go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module github.com/nephio-project/nephio/krm-functions/nfdeploy-fn
22

3-
go 1.20
3+
go 1.22
44

55
replace github.com/nephio-project/nephio/krm-functions/lib => ../lib
66

krm-functions/pipeline-tests/go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module github.com/nephio-project/nephio/krm-functions/pipeline-tests
22

3-
go 1.20
3+
go 1.22
44

55
// always test the latest versions of all functions/libs
66
replace (

krm-functions/ueransim-deploy-fn/Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
FROM golang:1.20-alpine
15+
FROM golang:1.22-alpine
1616
ENV CGO_ENABLED=0
1717
WORKDIR /go/src/
1818
COPY krm-functions/ krm-functions/

0 commit comments

Comments
 (0)