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

Upgrade Nephio to Go 1.22 #597

Merged
merged 4 commits into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

.SHELLFLAGS = -ec

GO_VERSION ?= 1.20.2
GO_VERSION ?= 1.22.2
IMG_REGISTRY ?= docker.io/nephio

# find all subdirectories with a go.mod file in them
Expand Down
2 changes: 1 addition & 1 deletion controllers/pkg/cluster/capi/capi.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func (r *Capi) isCapiClusterReady(ctx context.Context) bool {
r.l = log.FromContext(ctx)
name := r.GetClusterName()

cl := resource.GetUnstructuredFromGVK(&schema.GroupVersionKind{Group: capiv1beta1.GroupVersion.Group, Version: capiv1beta1.GroupVersion.Version, Kind: reflect.TypeOf(capiv1beta1.Cluster{}).Name()})
cl := resource.GetUnstructuredFromGVK(&schema.GroupVersionKind{Group: capiv1beta1.GroupVersion.Group, Version: capiv1beta1.GroupVersion.Version, Kind: reflect.TypeFor[capiv1beta1.Cluster]().Name()})
if err := r.Get(ctx, types.NamespacedName{Namespace: r.Secret.GetNamespace(), Name: name}, cl); err != nil {
r.l.Error(err, "cannot get cluster")
return false
Expand Down
2 changes: 1 addition & 1 deletion controllers/pkg/go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/nephio-project/nephio/controllers/pkg

go 1.20
go 1.22

replace (
github.com/GoogleContainerTools/kpt/porch => github.com/GoogleContainerTools/kpt/porch v0.0.0-20230526213300-77a54e3b8e88
Expand Down
7 changes: 4 additions & 3 deletions controllers/pkg/porch/util/packagevariant_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,15 @@ package util

import (
"context"
"reflect"
"testing"

porchapi "github.com/GoogleContainerTools/kpt/porch/api/porch/v1alpha1"
pvapi "github.com/GoogleContainerTools/kpt/porch/controllers/packagevariants/api/v1alpha1"
"github.com/stretchr/testify/require"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"reflect"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/yaml"
"testing"
)

type fakeClient struct {
Expand Down Expand Up @@ -67,7 +68,7 @@ func TestPackageRevisionIsReady(t *testing.T) {
{
APIVersion: "config.porch.kpt.dev/v1alpha1",
Controller: &tr,
Kind: reflect.TypeOf(pvapi.PackageVariant{}).Name(),
Kind: reflect.TypeFor[pvapi.PackageVariant]().Name(),
Name: "wc-argocd-argocd-cluster",
},
},
Expand Down
2 changes: 1 addition & 1 deletion controllers/pkg/reconcilers/token/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ func (r *reconciler) createToken(ctx context.Context, giteaClient giteaclient.Gi
secret := &corev1.Secret{
TypeMeta: metav1.TypeMeta{
APIVersion: corev1.SchemeGroupVersion.Identifier(),
Kind: reflect.TypeOf(corev1.Secret{}).Name(),
Kind: reflect.TypeFor[corev1.Secret]().Name(),
},
ObjectMeta: metav1.ObjectMeta{
Namespace: cr.GetNamespace(),
Expand Down
2 changes: 1 addition & 1 deletion default-go-lint.mk
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# limitations under the License.


GOLANG_CI_VER ?= v1.52
GOLANG_CI_VER ?= v1.57
GIT_ROOT_DIR ?= $(dir $(lastword $(MAKEFILE_LIST)))
include $(GIT_ROOT_DIR)/detect-container-runtime.mk

Expand Down
4 changes: 2 additions & 2 deletions default-go-test.mk
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# limitations under the License.


GO_VERSION ?= 1.20.2
GO_VERSION ?= 1.22.2
TEST_COVERAGE_FILE=lcov.info
TEST_COVERAGE_HTML_FILE=coverage_unit.html
TEST_COVERAGE_FUNC_FILE=func_coverage.out
Expand All @@ -28,7 +28,7 @@ unit: test
.PHONY: test
test: ## Run unit tests (go test)
ifeq ($(CONTAINER_RUNNABLE), 0)
$(RUN_CONTAINER_COMMAND) docker.io/library/golang:${GO_VERSION}-alpine3.17 \
$(RUN_CONTAINER_COMMAND) docker.io/library/golang:${GO_VERSION}-alpine3.19 \
sh -e -c "go test ./... -v -coverprofile ${TEST_COVERAGE_FILE}; \
go tool cover -html=${TEST_COVERAGE_FILE} -o ${TEST_COVERAGE_HTML_FILE}; \
go tool cover -func=${TEST_COVERAGE_FILE} -o ${TEST_COVERAGE_FUNC_FILE}"
Expand Down
2 changes: 1 addition & 1 deletion krm-functions/configinject-fn/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

FROM golang:1.20-alpine
FROM golang:1.22-alpine
ENV CGO_ENABLED=0
WORKDIR /go/src/
COPY krm-functions/ krm-functions/
Expand Down
2 changes: 1 addition & 1 deletion krm-functions/configinject-fn/fn/function.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func New(c client.Client) *FnR {
Owns: map[corev1.ObjectReference]condkptsdk.ResourceKind{
{
APIVersion: nephiorefv1alpha1.GroupVersion.Identifier(),
Kind: reflect.TypeOf(nephiorefv1alpha1.Config{}).Name(),
Kind: reflect.TypeFor[nephiorefv1alpha1.Config]().Name(),
}: condkptsdk.ChildLocal,
},
Watch: map[corev1.ObjectReference]condkptsdk.WatchCallbackFn{
Expand Down
2 changes: 1 addition & 1 deletion krm-functions/configinject-fn/go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/nephio-project/nephio/krm-functions/configinject-fn

go 1.20
go 1.22

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

Expand Down
2 changes: 1 addition & 1 deletion krm-functions/dnn-fn/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

FROM golang:1.20-alpine
FROM golang:1.22-alpine
ENV CGO_ENABLED=0
WORKDIR /go/src/
COPY krm-functions/ krm-functions/
Expand Down
2 changes: 1 addition & 1 deletion krm-functions/dnn-fn/fn/function.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func Run(rl *fn.ResourceList) (bool, error) {
Watch: map[corev1.ObjectReference]condkptsdk.WatchCallbackFn{
{
APIVersion: infrav1alpha1.GroupVersion.Identifier(),
Kind: reflect.TypeOf(infrav1alpha1.WorkloadCluster{}).Name(),
Kind: reflect.TypeFor[infrav1alpha1.WorkloadCluster]().Name(),
}: myFn.WorkloadClusterCallbackFn,
},
PopulateOwnResourcesFn: myFn.desiredOwnedResourceList,
Expand Down
2 changes: 1 addition & 1 deletion krm-functions/dnn-fn/go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/nephio-project/nephio/krm-functions/dnn-fn

go 1.20
go 1.22

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

Expand Down
2 changes: 1 addition & 1 deletion krm-functions/gen-configmap-fn/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

FROM golang:1.20-alpine
FROM golang:1.22-alpine
ENV CGO_ENABLED=0
WORKDIR /go/src/
COPY krm-functions/ krm-functions/
Expand Down
2 changes: 1 addition & 1 deletion krm-functions/gen-configmap-fn/go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/nephio-project/nephio/krm-functions/gen-configmap-fn

go 1.20
go 1.22

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

Expand Down
2 changes: 1 addition & 1 deletion krm-functions/interface-fn/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

FROM golang:1.20-alpine
FROM golang:1.22-alpine
ENV CGO_ENABLED=0
WORKDIR /go/src/
COPY krm-functions/ krm-functions/
Expand Down
6 changes: 3 additions & 3 deletions krm-functions/interface-fn/fn/function.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func Run(rl *fn.ResourceList) (bool, error) {
Owns: map[corev1.ObjectReference]condkptsdk.ResourceKind{
{
APIVersion: nadv1.SchemeGroupVersion.Identifier(),
Kind: reflect.TypeOf(nadv1.NetworkAttachmentDefinition{}).Name(),
Kind: reflect.TypeFor[nadv1.NetworkAttachmentDefinition]().Name(),
}: condkptsdk.ChildRemoteCondition,
{
APIVersion: ipamv1alpha1.GroupVersion.Identifier(),
Expand All @@ -70,7 +70,7 @@ func Run(rl *fn.ResourceList) (bool, error) {
Watch: map[corev1.ObjectReference]condkptsdk.WatchCallbackFn{
{
APIVersion: infrav1alpha1.GroupVersion.Identifier(),
Kind: reflect.TypeOf(infrav1alpha1.WorkloadCluster{}).Name(),
Kind: reflect.TypeFor[infrav1alpha1.WorkloadCluster]().Name(),
}: myFn.WorkloadClusterCallbackFn,
},
PopulateOwnResourcesFn: myFn.desiredOwnedResourceList,
Expand Down Expand Up @@ -289,7 +289,7 @@ func BuildNetworkAttachmentDefinition(meta metav1.ObjectMeta, spec nadv1.Network
return &nadv1.NetworkAttachmentDefinition{
TypeMeta: metav1.TypeMeta{
APIVersion: nadv1.SchemeGroupVersion.Identifier(),
Kind: reflect.TypeOf(nadv1.NetworkAttachmentDefinition{}).Name(),
Kind: reflect.TypeFor[nadv1.NetworkAttachmentDefinition]().Name(),
},
ObjectMeta: meta,
Spec: spec,
Expand Down
2 changes: 1 addition & 1 deletion krm-functions/interface-fn/go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/nephio-project/nephio/krm-functions/interface-fn

go 1.20
go 1.22

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

Expand Down
2 changes: 1 addition & 1 deletion krm-functions/ipam-fn/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

FROM golang:1.20-alpine
FROM golang:1.22-alpine
ENV CGO_ENABLED=0
WORKDIR /go/src/
COPY krm-functions/ krm-functions/
Expand Down
2 changes: 1 addition & 1 deletion krm-functions/ipam-fn/go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/nephio-project/nephio/krm-functions/ipam-fn

go 1.20
go 1.22

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

Expand Down
3 changes: 3 additions & 0 deletions krm-functions/lib/condkptsdk/sdk_stage1_update_children.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ func (r *sdk) updateChildren() {
for _, obj := range diff.createObjs {
if r.debug {
fn.Logf("stage1: diff action -> create obj: ref: %s, ownkind: %s\n", kptfilelibv1.GetConditionType(&obj.ref), obj.ownKind)
// #nosec G601
}
status := kptv1.ConditionFalse
if obj.ownKind == ChildLocal {
Expand All @@ -151,6 +152,7 @@ func (r *sdk) updateChildren() {
for _, obj := range diff.updateObjs {
if r.debug {
fn.Logf("stage1: diff action -> update obj: %s\n", kptfilelibv1.GetConditionType(&obj.ref))
// #nosec G601
}
if err := r.upsertChildObject(ownGVKKind, []corev1.ObjectReference{forRef, obj.ref}, obj, nil, "update resource", kptv1.ConditionFalse, false); err != nil {
// the errors are already logged, we set the result in the for condition
Expand All @@ -163,6 +165,7 @@ func (r *sdk) updateChildren() {
for _, obj := range diff.deleteObjs {
if r.debug {
fn.Logf("stage1: diff action -> delete obj: %s\n", kptfilelibv1.GetConditionType(&obj.ref))
// #nosec G601
}
if err := r.deleteChildObject(ownGVKKind, []corev1.ObjectReference{forRef, obj.ref}, obj, "delete resource"); err != nil {
// the errors are already logged, we set the result in the for condition
Expand Down
2 changes: 1 addition & 1 deletion krm-functions/lib/go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/nephio-project/nephio/krm-functions/lib

go 1.20
go 1.22

require (
github.com/GoogleContainerTools/kpt v1.0.0-beta.29.0.20230327202912-01513604feaa
Expand Down
3 changes: 1 addition & 2 deletions krm-functions/lib/kubeobject/kubeobject.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,7 @@ func (o *KubeObjectExt[T1]) getFieldOrPanic(value *T1, fieldName string) interfa
}

func validateTypeOrPanic[T1 any]() {
var x T1
v := reflect.TypeOf(x)
v := reflect.TypeFor[T1]()
if v.Kind() != reflect.Struct {
panic(fmt.Sprintf("type %q is not a struct", v.Name()))
}
Expand Down
3 changes: 1 addition & 2 deletions krm-functions/lib/kubeobject/lists.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,7 @@ func GetSingleton[T any, PT PtrIsRuntimeObject[T]](objs fn.KubeObjects) (*T, err
return nil, err
}
if len(typedObjs) != 1 {
var x T
return nil, fmt.Errorf("expected exactly 1 instance of %v in the kpt package, but got %v", reflect.TypeOf(x).Name(), len(typedObjs))
return nil, fmt.Errorf("expected exactly 1 instance of %v in the kpt package, but got %v", reflect.TypeFor[T]().Name(), len(typedObjs))
}
return typedObjs[0], nil
}
7 changes: 4 additions & 3 deletions krm-functions/lib/nad/v1/nad_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,15 @@ limitations under the License.
package v1

import (
"reflect"
"testing"

"github.com/GoogleContainerTools/kpt-functions-sdk/go/fn"
"github.com/google/go-cmp/cmp"
nadv1 "github.com/k8snetworkplumbingwg/network-attachment-definition-client/pkg/apis/k8s.cni.cncf.io/v1"
"github.com/stretchr/testify/assert"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"reflect"
"sigs.k8s.io/yaml"
"testing"
)

var nadTestSriov = `apiVersion: "k8s.cni.cncf.io/v1"
Expand Down Expand Up @@ -105,7 +106,7 @@ func TestNewFromGoStruct(t *testing.T) {
input: &nadv1.NetworkAttachmentDefinition{
TypeMeta: metav1.TypeMeta{
APIVersion: nadv1.SchemeGroupVersion.Identifier(),
Kind: reflect.TypeOf(nadv1.NetworkAttachmentDefinition{}).Name(),
Kind: reflect.TypeFor[nadv1.NetworkAttachmentDefinition]().Name(),
},
ObjectMeta: metav1.ObjectMeta{
Name: "a",
Expand Down
2 changes: 1 addition & 1 deletion krm-functions/nad-fn/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

FROM golang:1.20-alpine
FROM golang:1.22-alpine
ENV CGO_ENABLED=0
WORKDIR /go/src/
COPY krm-functions/ krm-functions/
Expand Down
4 changes: 2 additions & 2 deletions krm-functions/nad-fn/fn/function.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func Run(rl *fn.ResourceList) (bool, error) {
&condkptsdk.Config{
For: corev1.ObjectReference{
APIVersion: nadv1.SchemeGroupVersion.Identifier(),
Kind: reflect.TypeOf(nadv1.NetworkAttachmentDefinition{}).Name(),
Kind: reflect.TypeFor[nadv1.NetworkAttachmentDefinition]().Name(),
},
Watch: map[corev1.ObjectReference]condkptsdk.WatchCallbackFn{
{
Expand Down Expand Up @@ -168,7 +168,7 @@ func (f *nadFn) updateResourceFn(_ *fn.KubeObject, objs fn.KubeObjects) (fn.Kube
nad, err := nadlibv1.NewFromGoStruct(&nadv1.NetworkAttachmentDefinition{
TypeMeta: metav1.TypeMeta{
APIVersion: nadv1.SchemeGroupVersion.Identifier(),
Kind: reflect.TypeOf(nadv1.NetworkAttachmentDefinition{}).Name(),
Kind: reflect.TypeFor[nadv1.NetworkAttachmentDefinition]().Name(),
},
ObjectMeta: metav1.ObjectMeta{Name: fmt.Sprintf("%s-%s", f.forName, interfaceObjs[0].GetName()), Namespace: f.forNamespace},
})
Expand Down
2 changes: 1 addition & 1 deletion krm-functions/nad-fn/go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/nephio-project/nephio/krm-functions/nad-fn

go 1.20
go 1.22

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

Expand Down
2 changes: 1 addition & 1 deletion krm-functions/nfdeploy-fn/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

FROM golang:1.20-alpine
FROM golang:1.22-alpine
ENV CGO_ENABLED=0
WORKDIR /go/src/
COPY krm-functions/ krm-functions/
Expand Down
2 changes: 1 addition & 1 deletion krm-functions/nfdeploy-fn/fn/function.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func Run(rl *fn.ResourceList) (bool, error) {
Watch: map[corev1.ObjectReference]condkptsdk.WatchCallbackFn{
{
APIVersion: infrav1alpha1.GroupVersion.Identifier(),
Kind: reflect.TypeOf(infrav1alpha1.WorkloadCluster{}).Name(),
Kind: reflect.TypeFor[infrav1alpha1.WorkloadCluster]().Name(),
}: nfDeployFn.WorkloadClusterCallbackFn,
},
PopulateOwnResourcesFn: nfDeployFn.desiredOwnedResourceList,
Expand Down
2 changes: 1 addition & 1 deletion krm-functions/nfdeploy-fn/go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/nephio-project/nephio/krm-functions/nfdeploy-fn

go 1.20
go 1.22

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

Expand Down
2 changes: 1 addition & 1 deletion krm-functions/pipeline-tests/go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/nephio-project/nephio/krm-functions/pipeline-tests

go 1.20
go 1.22

// always test the latest versions of all functions/libs
replace (
Expand Down
2 changes: 1 addition & 1 deletion krm-functions/ueransim-deploy-fn/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

FROM golang:1.20-alpine
FROM golang:1.22-alpine
ENV CGO_ENABLED=0
WORKDIR /go/src/
COPY krm-functions/ krm-functions/
Expand Down
Loading