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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 4 additions & 3 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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)