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

feat: upgrade to Go 1.20 #239

Merged
merged 4 commits into from
Aug 31, 2023
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
8 changes: 4 additions & 4 deletions .github/workflows/build-images-base.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,10 @@ jobs:
name: Build Bundle
runs-on: ubuntu-latest
steps:
- name: Set up Go 1.19.x
- name: Set up Go 1.20.x
uses: actions/setup-go@v4
with:
go-version: 1.19.x
go-version: 1.20.x
id: go
- name: Check out code
uses: actions/checkout@v3
Expand Down Expand Up @@ -147,10 +147,10 @@ jobs:
needs: [build, build-bundle]
runs-on: ubuntu-latest
steps:
- name: Set up Go 1.19.x
- name: Set up Go 1.20.x
uses: actions/setup-go@v4
with:
go-version: 1.19.x
go-version: 1.20.x
id: go
- name: Check out code
uses: actions/checkout@v3
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/code-style.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ jobs:
importpath: golang.org/x/tools/cmd/goimports@latest

steps:
- name: Set up Go 1.19.x
- name: Set up Go 1.20.x
uses: actions/setup-go@v4
with:
go-version: 1.19.x
go-version: 1.20.x
id: go

- name: Check out code
Expand Down Expand Up @@ -90,10 +90,10 @@ jobs:
runs-on: ubuntu-latest

steps:
- name: Set up Go 1.19.x
- name: Set up Go 1.20.x
uses: actions/setup-go@v4
with:
go-version: 1.19.x
go-version: 1.20.x
id: go

- name: Check out code
Expand Down
20 changes: 10 additions & 10 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
name: Unit Tests
strategy:
matrix:
go-version: [ 1.19.x ]
go-version: [ 1.20.x ]
platform: [ ubuntu-latest ]
runs-on: ${{ matrix.platform }}
defaults:
Expand Down Expand Up @@ -53,10 +53,10 @@ jobs:
run:
shell: bash
steps:
- name: Set up Go 1.19.x
- name: Set up Go 1.20.x
uses: actions/setup-go@v4
with:
go-version: 1.19.x
go-version: 1.20.x
id: go
- name: Check out code
uses: actions/checkout@v3
Expand Down Expand Up @@ -94,10 +94,10 @@ jobs:
name: Verify manifests
runs-on: ubuntu-latest
steps:
- name: Set up Go 1.19.x
- name: Set up Go 1.20.x
uses: actions/setup-go@v4
with:
go-version: 1.19.x
go-version: 1.20.x
id: go
- name: Check out code
uses: actions/checkout@v3
Expand All @@ -109,10 +109,10 @@ jobs:
name: Verify bundle
runs-on: ubuntu-latest
steps:
- name: Set up Go 1.19.x
- name: Set up Go 1.20.x
uses: actions/setup-go@v4
with:
go-version: 1.19.x
go-version: 1.20.x
id: go
- name: Check out code
uses: actions/checkout@v3
Expand All @@ -124,10 +124,10 @@ jobs:
name: Verify fmt
runs-on: ubuntu-latest
steps:
- name: Set up Go 1.19.x
- name: Set up Go 1.20.x
uses: actions/setup-go@v4
with:
go-version: 1.19.x
go-version: 1.20.x
id: go
- name: Check out code
uses: actions/checkout@v3
Expand All @@ -139,7 +139,7 @@ jobs:
name: Test Scripts
strategy:
matrix:
go-version: [ 1.19.x ]
go-version: [ 1.20.x ]
platform: [ ubuntu-latest, macos-latest ]
runs-on: ${{ matrix.platform }}
defaults:
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Build the manager binary
FROM golang:1.19 as builder
FROM golang:1.20 as builder

WORKDIR /workspace
# Copy the Go Modules manifests
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ run-lint: $(GOLANGCI-LINT) ## Run lint tests
$(GOLANGCI-LINT) run

$(GOLANGCI-LINT):
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(PROJECT_PATH)/bin v1.50.1
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(PROJECT_PATH)/bin v1.54.2

.PHONY: golangci-lint
golangci-lint: $(GOLANGCI-LINT) ## Download golangci-lint locally if necessary.
Expand Down
28 changes: 14 additions & 14 deletions api/external/maistra/v1/helmvalues.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,24 @@ import (
// +kubebuilder:validation:Type=object
// +kubebuilder:validation:XPreserveUnknownFields
type HelmValues struct {
data map[string]interface{} `json:"-"`
data map[string]any `json:"-"`
}

func NewHelmValues(values map[string]interface{}) *HelmValues {
func NewHelmValues(values map[string]any) *HelmValues {
if values == nil {
values = make(map[string]interface{})
values = make(map[string]any)
}
return &HelmValues{data: values}
}

func (h *HelmValues) GetContent() map[string]interface{} {
func (h *HelmValues) GetContent() map[string]any {
if h == nil {
return nil
}
return h.data
}

func (h *HelmValues) GetFieldNoCopy(path string) (interface{}, bool, error) {
func (h *HelmValues) GetFieldNoCopy(path string) (any, bool, error) {
if h == nil || h.data == nil {
return nil, false, nil
}
Expand Down Expand Up @@ -193,7 +193,7 @@ func (h *HelmValues) GetAndRemoveStringSlice(path string) ([]string, bool, error
return value, ok, err
}

func (h *HelmValues) GetSlice(path string) ([]interface{}, bool, error) {
func (h *HelmValues) GetSlice(path string) ([]any, bool, error) {
if h == nil || h.data == nil {
return nil, false, nil
}
Expand All @@ -206,7 +206,7 @@ func (h *HelmValues) GetSlice(path string) ([]interface{}, bool, error) {
return slice, ok, err
}

func (h *HelmValues) GetAndRemoveSlice(path string) ([]interface{}, bool, error) {
func (h *HelmValues) GetAndRemoveSlice(path string) ([]any, bool, error) {
value, ok, err := h.GetSlice(path)
if err == nil {
h.RemoveField(path)
Expand Down Expand Up @@ -245,7 +245,7 @@ func (h *HelmValues) GetAndRemoveStringToStringMap(path string) (map[string]stri
return stringToStringMap, found, nil
}

func (h *HelmValues) GetMap(path string) (map[string]interface{}, bool, error) {
func (h *HelmValues) GetMap(path string) (map[string]any, bool, error) {
if h == nil || h.data == nil {
return nil, false, nil
}
Expand All @@ -254,15 +254,15 @@ func (h *HelmValues) GetMap(path string) (map[string]interface{}, bool, error) {
if rawval == nil {
return nil, ok, err
}
if mapval, ok := rawval.(map[string]interface{}); ok {
if mapval, ok := rawval.(map[string]any); ok {
return mapval, ok, err
}
return nil, false, fmt.Errorf("%v accessor error: %v is of the type %T, expected map[string]interface{}", path, rawval, rawval)
return nil, false, fmt.Errorf("%v accessor error: %v is of the type %T, expected map[string]any", path, rawval, rawval)
}
return nil, ok, err
}

func (h *HelmValues) GetAndRemoveMap(path string) (map[string]interface{}, bool, error) {
func (h *HelmValues) GetAndRemoveMap(path string) (map[string]any, bool, error) {
value, ok, err := h.GetMap(path)
if err == nil {
h.RemoveField(path)
Expand All @@ -289,12 +289,12 @@ func (h *HelmValues) GetAndRemoveStringMap(path string) (map[string]string, bool
return value, ok, err
}

func (h *HelmValues) SetField(path string, value interface{}) error {
func (h *HelmValues) SetField(path string, value any) error {
if h == nil {
panic("Tried to invoke SetField on nil *HelmValues")
}
if h.data == nil {
h.data = map[string]interface{}{}
h.data = map[string]any{}
}
return unstructured.SetNestedField(h.data, value, strings.Split(path, ".")...)
}
Expand All @@ -304,7 +304,7 @@ func (h *HelmValues) SetStringSlice(path string, value []string) error {
panic("Tried to invoke SetField on nil *HelmValues")
}
if h.data == nil {
h.data = map[string]interface{}{}
h.data = map[string]any{}
}
return unstructured.SetNestedStringSlice(h.data, value, strings.Split(path, ".")...)
}
Expand Down
2 changes: 1 addition & 1 deletion controllers/authpolicy_auth_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func (r *AuthPolicyReconciler) policyHosts(ap *api.AuthPolicy, targetNetworkObje
return common.TargetHostnames(targetNetworkObject)
}

uniqueHostnamesMap := make(map[string]interface{})
uniqueHostnamesMap := make(map[string]any)
for idx := range ap.Spec.AuthRules {
if len(ap.Spec.AuthRules[idx].Hosts) == 0 {
// When one of the rules does not have hosts, just return target hostnames
Expand Down
6 changes: 3 additions & 3 deletions controllers/authpolicy_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ func (r *AuthPolicyReconciler) deleteResources(ctx context.Context, ap *api.Auth

// remove direct back ref
if targetNetworkObject != nil {
if err := r.deleteNetworkResourceDirectBackReference(ctx, ap, targetNetworkObject); err != nil {
if err := r.deleteNetworkResourceDirectBackReference(ctx, targetNetworkObject); err != nil {
return err
}
}
Expand All @@ -186,8 +186,8 @@ func (r *AuthPolicyReconciler) reconcileNetworkResourceDirectBackReference(ctx c
return r.ReconcileTargetBackReference(ctx, client.ObjectKeyFromObject(ap), targetNetworkObject, common.AuthPolicyBackRefAnnotation)
}

func (r *AuthPolicyReconciler) deleteNetworkResourceDirectBackReference(ctx context.Context, ap *api.AuthPolicy, targetNetworkObject client.Object) error {
return r.DeleteTargetBackReference(ctx, client.ObjectKeyFromObject(ap), targetNetworkObject, common.AuthPolicyBackRefAnnotation)
func (r *AuthPolicyReconciler) deleteNetworkResourceDirectBackReference(ctx context.Context, targetNetworkObject client.Object) error {
return r.DeleteTargetBackReference(ctx, targetNetworkObject, common.AuthPolicyBackRefAnnotation)
}

// SetupWithManager sets up the controller with the Manager.
Expand Down
4 changes: 1 addition & 3 deletions controllers/authpolicy_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -428,9 +428,7 @@ func testBasicAuthScheme() kuadrantv1beta1.AuthSchemeSpec {
},
},
Credentials: authorinov1beta1.Credentials{
In: authorinov1beta1.Credentials_In(
"authorization_header",
),
In: "authorization_header",
KeySelector: "APIKEY",
},
},
Expand Down
14 changes: 8 additions & 6 deletions controllers/authpolicy_istio_authorization_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"reflect"

"github.com/go-logr/logr"
"golang.org/x/exp/slices"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This slice package (https://pkg.go.dev/golang.org/x/[email protected]/slices) is provided as part of Go 1.21 standard library https://pkg.go.dev/[email protected] but is not available in Go 1.20

apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
Expand All @@ -19,9 +20,10 @@ import (
api "github.com/kuadrant/kuadrant-operator/api/v1beta1"
"github.com/kuadrant/kuadrant-operator/pkg/common"
"github.com/kuadrant/kuadrant-operator/pkg/reconcilers"
"k8s.io/utils/env"
)

var KuadrantExtAuthProviderName = common.FetchEnv("AUTH_PROVIDER", "kuadrant-authorization")
var KuadrantExtAuthProviderName = env.GetString("AUTH_PROVIDER", "kuadrant-authorization")

// reconcileIstioAuthorizationPolicies translates and reconciles `AuthRules` into an Istio AuthorizationPoilcy containing them.
func (r *AuthPolicyReconciler) reconcileIstioAuthorizationPolicies(ctx context.Context, ap *api.AuthPolicy, targetNetworkObject client.Object, gwDiffObj *reconcilers.GatewayDiff) error {
Expand Down Expand Up @@ -63,15 +65,15 @@ func (r *AuthPolicyReconciler) deleteIstioAuthorizationPolicies(ctx context.Cont
}

for _, gw := range gwDiffObj.GatewaysWithInvalidPolicyRef {
listOptions := &client.ListOptions{LabelSelector: labels.SelectorFromSet(labels.Set(istioAuthorizationPolicyLabels(client.ObjectKeyFromObject(gw.Gateway), client.ObjectKeyFromObject(ap))))}
listOptions := &client.ListOptions{LabelSelector: labels.SelectorFromSet(istioAuthorizationPolicyLabels(client.ObjectKeyFromObject(gw.Gateway), client.ObjectKeyFromObject(ap)))}
iapList := &istio.AuthorizationPolicyList{}
if err := r.Client().List(ctx, iapList, listOptions); err != nil {
return err
}

for _, iap := range iapList.Items {
// it's OK to just go ahead and delete because we only create one IAP per target network object,
// and a network object can be target by no more than one AuthPolicy
// and a network object can be targeted by no more than one AuthPolicy
if err := r.DeleteResource(ctx, iap); err != nil && !apierrors.IsNotFound(err) {
logger.Error(err, "failed to delete IstioAuthorizationPolicy")
return err
Expand Down Expand Up @@ -155,9 +157,9 @@ func istioAuthorizationPolicyRules(authRules []api.AuthRule, targetHostnames []s
for idx := range httpRouterules {
toRules = append(toRules, &istiosecurity.Rule_To{
Operation: &istiosecurity.Operation{
Hosts: common.SliceCopy(httpRouterules[idx].Hosts),
Methods: common.SliceCopy(httpRouterules[idx].Methods),
Paths: common.SliceCopy(httpRouterules[idx].Paths),
Hosts: slices.Clone(httpRouterules[idx].Hosts),
Methods: slices.Clone(httpRouterules[idx].Methods),
Paths: slices.Clone(httpRouterules[idx].Paths),
},
})
}
Expand Down
12 changes: 6 additions & 6 deletions controllers/authpolicy_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import (
"github.com/go-logr/logr"
authorinov1beta1 "github.com/kuadrant/authorino/api/v1beta1"
kuadrantv1beta1 "github.com/kuadrant/kuadrant-operator/api/v1beta1"
"github.com/kuadrant/kuadrant-operator/pkg/common"
"golang.org/x/exp/slices"
"k8s.io/apimachinery/pkg/api/errors"
meta "k8s.io/apimachinery/pkg/api/meta"
"k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
Expand Down Expand Up @@ -73,20 +73,20 @@ func (r *AuthPolicyReconciler) reconcileStatus(ctx context.Context, ap *kuadrant

func (r *AuthPolicyReconciler) calculateStatus(ap *kuadrantv1beta1.AuthPolicy, specErr error, authConfigReady bool) *kuadrantv1beta1.AuthPolicyStatus {
newStatus := &kuadrantv1beta1.AuthPolicyStatus{
Conditions: common.CopyConditions(ap.Status.Conditions),
Conditions: slices.Clone(ap.Status.Conditions),
ObservedGeneration: ap.Status.ObservedGeneration,
}

targetNetworkObjectectKind := string(ap.Spec.TargetRef.Kind)
availableCond := r.availableCondition(targetNetworkObjectectKind, specErr, authConfigReady)
targetNetworkObjectKind := string(ap.Spec.TargetRef.Kind)
availableCond := r.availableCondition(targetNetworkObjectKind, specErr, authConfigReady)

meta.SetStatusCondition(&newStatus.Conditions, *availableCond)

return newStatus
}

func (r *AuthPolicyReconciler) availableCondition(targetNetworkObjectectKind string, specErr error, authConfigReady bool) *metav1.Condition {
// Condition if there is not issue
// Condition if there is no issue
cond := &metav1.Condition{
Type: APAvailableConditionType,
Status: metav1.ConditionTrue,
Expand Down
2 changes: 1 addition & 1 deletion controllers/helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
. "github.com/onsi/gomega"
v1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
meta "k8s.io/apimachinery/pkg/api/meta"
"k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/serializer"
Expand Down
Loading