diff --git a/Makefile b/Makefile index 3b835b9f6d7..e0a453e00bf 100644 --- a/Makefile +++ b/Makefile @@ -50,7 +50,7 @@ YAML_PATCH_BIN := yaml-patch YAML_PATCH := $(TOOLS_DIR)/$(YAML_PATCH_BIN)-$(YAML_PATCH_VER) export YAML_PATCH # so hack scripts can use it -GOLANGCI_LINT_VER := v2.1.6 +GOLANGCI_LINT_VER := v2.6.0 GOLANGCI_LINT_BIN := golangci-lint GOLANGCI_LINT := $(TOOLS_GOBIN_DIR)/$(GOLANGCI_LINT_BIN)-$(GOLANGCI_LINT_VER) GOLANGCI_LINT_FLAGS ?= @@ -63,7 +63,7 @@ GOTESTSUM_VER := v1.12.3 GOTESTSUM_BIN := gotestsum GOTESTSUM := $(abspath $(TOOLS_DIR))/$(GOTESTSUM_BIN)-$(GOTESTSUM_VER) -LOGCHECK_VER := v0.9.0 +LOGCHECK_VER := d35c84c015fe03a1421e5f2ce1e3c0c3bc38d077 LOGCHECK_BIN := logcheck LOGCHECK := $(TOOLS_GOBIN_DIR)/$(LOGCHECK_BIN)-$(LOGCHECK_VER) export LOGCHECK # so hack scripts can use it diff --git a/pkg/network/dialer_linux.go b/pkg/network/dialer_linux.go index 654af5788ff..4078d642037 100644 --- a/pkg/network/dialer_linux.go +++ b/pkg/network/dialer_linux.go @@ -1,5 +1,4 @@ //go:build linux -// +build linux /* Copyright 2024 The KCP Authors. diff --git a/pkg/network/dialer_other.go b/pkg/network/dialer_other.go index 0e472f859a2..0f15c104ad8 100644 --- a/pkg/network/dialer_other.go +++ b/pkg/network/dialer_other.go @@ -1,5 +1,4 @@ //go:build !linux -// +build !linux /* Copyright 2024 The KCP Authors. diff --git a/staging/src/github.com/kcp-dev/sdk/apis/apis/v1alpha1/types_apiexportendpointslice.go b/staging/src/github.com/kcp-dev/sdk/apis/apis/v1alpha1/types_apiexportendpointslice.go index 7708d4a98bf..52915253911 100644 --- a/staging/src/github.com/kcp-dev/sdk/apis/apis/v1alpha1/types_apiexportendpointslice.go +++ b/staging/src/github.com/kcp-dev/sdk/apis/apis/v1alpha1/types_apiexportendpointslice.go @@ -116,6 +116,7 @@ const ( PartitionValid conditionsv1alpha1.ConditionType = "PartitionValid" // EndpointURLsReady is a condition for APIExportEndpointSlice that reflects the readiness of the URLs. + // // Deprecated: This condition is deprecated and will be removed in a future release. APIExportEndpointSliceURLsReady conditionsv1alpha1.ConditionType = "EndpointURLsReady" diff --git a/staging/src/github.com/kcp-dev/sdk/apis/cache/v1alpha1/types_cachedresourceendpointslice.go b/staging/src/github.com/kcp-dev/sdk/apis/cache/v1alpha1/types_cachedresourceendpointslice.go index 004dbe243ae..edfc3ec2669 100644 --- a/staging/src/github.com/kcp-dev/sdk/apis/cache/v1alpha1/types_cachedresourceendpointslice.go +++ b/staging/src/github.com/kcp-dev/sdk/apis/cache/v1alpha1/types_cachedresourceendpointslice.go @@ -110,6 +110,7 @@ const ( PartitionValid conditionsv1alpha1.ConditionType = "PartitionValid" // EndpointURLsReady is a condition for CachedResourceEndpointSlice that reflects the readiness of the URLs. + // // Deprecated: This condition is deprecated and will be removed in a future release. CachedResourceEndpointSliceURLsReady conditionsv1alpha1.ConditionType = "EndpointURLsReady" diff --git a/staging/src/github.com/kcp-dev/sdk/testing/server/fixture.go b/staging/src/github.com/kcp-dev/sdk/testing/server/fixture.go index af02ba5b4dc..4525fbd6474 100644 --- a/staging/src/github.com/kcp-dev/sdk/testing/server/fixture.go +++ b/staging/src/github.com/kcp-dev/sdk/testing/server/fixture.go @@ -58,6 +58,7 @@ const kcpBinariesDirEnvDir = "KCP_BINARIES_DIR" // RunInProcessFunc instantiates the kcp server in process for easier debugging. // It is here to decouple the rest of the code from kcp core dependencies. +// // Deprecated: Use ContextRunInProcessFunc instead. var RunInProcessFunc func(t TestingT, dataDir string, args []string) (<-chan struct{}, error) diff --git a/test/e2e/conformance/cross_logical_cluster_list_test.go b/test/e2e/conformance/cross_logical_cluster_list_test.go index 95fc071ab17..d37939a7396 100644 --- a/test/e2e/conformance/cross_logical_cluster_list_test.go +++ b/test/e2e/conformance/cross_logical_cluster_list_test.go @@ -19,6 +19,7 @@ package conformance import ( "context" "fmt" + "strings" "testing" "time" @@ -27,6 +28,7 @@ import ( corev1 "k8s.io/api/core/v1" apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" "k8s.io/apimachinery/pkg/labels" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime/schema" @@ -45,6 +47,7 @@ import ( tenancyv1alpha1 "github.com/kcp-dev/sdk/apis/tenancy/v1alpha1" kcpclientset "github.com/kcp-dev/sdk/client/clientset/versioned/cluster" kcptesting "github.com/kcp-dev/sdk/testing" + kcptestinghelpers "github.com/kcp-dev/sdk/testing/helpers" configcrds "github.com/kcp-dev/kcp/config/crds" "github.com/kcp-dev/kcp/pkg/informer" @@ -196,20 +199,20 @@ func TestCRDCrossLogicalClusterListPartialObjectMetadata(t *testing.T) { t.Logf("Install a different sheriffs CRD into workspace %q", wsNormalCRD2) bootstrapCRD(t, wsNormalCRD2, crdClusterClient.ApiextensionsV1().CustomResourceDefinitions(), sheriffCRD2) - apifixtures.CreateSheriff(ctx, t, dynamicClusterClient, wsNormalCRD1a, group, wsNormalCRD1a.String()) - apifixtures.CreateSheriff(ctx, t, dynamicClusterClient, wsNormalCRD1b, group, wsNormalCRD1b.String()) + createSheriff(ctx, t, dynamicClusterClient, wsNormalCRD1a, group) + createSheriff(ctx, t, dynamicClusterClient, wsNormalCRD1b, group) apifixtures.CreateSheriffsSchemaAndExport(ctx, t, wsExport1a, kcpClusterClient, group, "export1") apifixtures.BindToExport(ctx, t, wsExport1a, group, wsConsume1a, kcpClusterClient) - apifixtures.CreateSheriff(ctx, t, dynamicClusterClient, wsConsume1a, group, wsConsume1a.String()) + createSheriff(ctx, t, dynamicClusterClient, wsConsume1a, group) apifixtures.CreateSheriffsSchemaAndExport(ctx, t, wsExport1b, kcpClusterClient, group, "export1") apifixtures.BindToExport(ctx, t, wsExport1b, group, wsConsume1b, kcpClusterClient) - apifixtures.CreateSheriff(ctx, t, dynamicClusterClient, wsConsume1b, group, wsConsume1b.String()) + createSheriff(ctx, t, dynamicClusterClient, wsConsume1b, group) apifixtures.CreateSheriffsSchemaAndExport(ctx, t, wsExport2, kcpClusterClient, group, "export2") apifixtures.BindToExport(ctx, t, wsExport2, group, wsConsume2, kcpClusterClient) - apifixtures.CreateSheriff(ctx, t, dynamicClusterClient, wsConsume2, group, wsConsume2.String()) + createSheriff(ctx, t, dynamicClusterClient, wsConsume2, group) t.Logf("Trying to wildcard list with PartialObjectMetadata content-type and it should work") rootShardMetadataClusterClient, err := metadataclient.NewDynamicMetadataClusterClientForConfig(rootShardConfig) @@ -321,3 +324,32 @@ func TestBuiltInCrossLogicalClusterListPartialObjectMetadata(t *testing.T) { require.Subset(t, sets.List[string](names), expected) } + +func createSheriff( + ctx context.Context, + t *testing.T, + dynamicClusterClient kcpdynamic.ClusterInterface, + clusterName logicalcluster.Path, + group string, +) { + t.Helper() + + name := strings.ReplaceAll(clusterName.String(), ":", "-") + + t.Logf("Creating %s/v1 sheriffs %s|default/%s", group, clusterName, name) + + sheriffsGVR := schema.GroupVersionResource{Group: group, Resource: "sheriffs", Version: "v1"} + + sheriff := &unstructured.Unstructured{} + sheriff.SetAPIVersion(group + "/v1") + sheriff.SetKind("Sheriff") + sheriff.SetName(name) + + // CRDs are asynchronously served because they are informer based. + kcptestinghelpers.Eventually(t, func() (bool, string) { + if _, err := dynamicClusterClient.Cluster(clusterName).Resource(sheriffsGVR).Namespace("default").Create(ctx, sheriff, metav1.CreateOptions{}); err != nil { + return false, fmt.Sprintf("failed to create Sheriff %s|%s: %v", clusterName, name, err.Error()) + } + return true, "" + }, wait.ForeverTestTimeout, time.Millisecond*100, "error creating Sheriff %s|%s", clusterName, name) +} diff --git a/test/e2e/fixtures/apifixtures/sheriffs.go b/test/e2e/fixtures/apifixtures/sheriffs.go index e3cf7f4616a..70f6d633aea 100644 --- a/test/e2e/fixtures/apifixtures/sheriffs.go +++ b/test/e2e/fixtures/apifixtures/sheriffs.go @@ -185,6 +185,7 @@ func CreateSheriffsSchemaAndExport( // CreateSheriff creates an instance of a Sheriff CustomResource in the logical cluster identified by clusterName, in // the specific API group, and with the specified name. +// // Deprecated: use local fixtures instead. func CreateSheriff( ctx context.Context, diff --git a/test/e2e/quota/quota_test.go b/test/e2e/quota/quota_test.go index 2fccd142423..91d68c625f4 100644 --- a/test/e2e/quota/quota_test.go +++ b/test/e2e/quota/quota_test.go @@ -19,6 +19,7 @@ package quota import ( "context" "fmt" + "strings" "testing" "time" @@ -314,15 +315,15 @@ func TestKubeQuotaNormalCRDs(t *testing.T) { }, wait.ForeverTestTimeout, 100*time.Millisecond, "error waiting for ws %d quota to show usage in status", wsIndex) t.Logf("Create 2 sheriffs to reach the quota limit") - apifixtures.CreateSheriff(ctx, t, dynamicClusterClient, ws, group, fmt.Sprintf("ws%d-1", wsIndex)) - apifixtures.CreateSheriff(ctx, t, dynamicClusterClient, ws, group, fmt.Sprintf("ws%d-2", wsIndex)) + createSheriff(ctx, t, dynamicClusterClient, ws, group, fmt.Sprintf("ws%d-1", wsIndex)) + createSheriff(ctx, t, dynamicClusterClient, ws, group, fmt.Sprintf("ws%d-2", wsIndex)) t.Logf("Make sure quota is enforcing limits") i := 0 sheriffsGVR := schema.GroupVersionResource{Group: group, Resource: "sheriffs", Version: "v1"} kcptestinghelpers.Eventually(t, func() (bool, string) { t.Logf("Trying to create a sheriff") - sheriff := NewSheriff(group, fmt.Sprintf("ws%d-%d", wsIndex, i)) + sheriff := newSheriff(group, fmt.Sprintf("ws%d-%d", wsIndex, i)) i++ _, err := dynamicClusterClient.Cluster(ws).Resource(sheriffsGVR).Namespace("default").Create(ctx, sheriff, metav1.CreateOptions{}) return apierrors.IsForbidden(err), fmt.Sprintf("expected a forbidden error, got: %v", err) @@ -461,15 +462,38 @@ func bootstrapCRD( require.NoError(t, err, "error bootstrapping CRD %s in cluster %s", crd.Name, clusterName) } -// NewSheriff returns a new *unstructured.Unstructured for a Sheriff with the given group and name. -func NewSheriff(group, name string) *unstructured.Unstructured { - return &unstructured.Unstructured{ - Object: map[string]interface{}{ - "apiVersion": group + "/v1", - "kind": "Sheriff", - "metadata": map[string]interface{}{ - "name": name, - }, - }, - } +// newSheriff returns a new *unstructured.Unstructured for a Sheriff with the given group and name. +func newSheriff(group, name string) *unstructured.Unstructured { + sheriff := &unstructured.Unstructured{} + sheriff.SetAPIVersion(group + "/v1") + sheriff.SetKind("Sheriff") + sheriff.SetName(name) + + return sheriff +} + +func createSheriff( + ctx context.Context, + t *testing.T, + dynamicClusterClient kcpdynamic.ClusterInterface, + clusterName logicalcluster.Path, + group, name string, +) { + t.Helper() + + name = strings.ReplaceAll(name, ":", "-") + + t.Logf("Creating %s/v1 sheriffs %s|default/%s", group, clusterName, name) + + sheriffsGVR := schema.GroupVersionResource{Group: group, Resource: "sheriffs", Version: "v1"} + + sheriff := newSheriff(group, name) + + // CRDs are asynchronously served because they are informer based. + kcptestinghelpers.Eventually(t, func() (bool, string) { + if _, err := dynamicClusterClient.Cluster(clusterName).Resource(sheriffsGVR).Namespace("default").Create(ctx, sheriff, metav1.CreateOptions{}); err != nil { + return false, fmt.Sprintf("failed to create Sheriff %s|%s: %v", clusterName, name, err.Error()) + } + return true, "" + }, wait.ForeverTestTimeout, time.Millisecond*100, "error creating Sheriff %s|%s", clusterName, name) } diff --git a/test/e2e/virtual/apiexport/virtualworkspace_test.go b/test/e2e/virtual/apiexport/virtualworkspace_test.go index f88761cf138..2f8be325aa9 100644 --- a/test/e2e/virtual/apiexport/virtualworkspace_test.go +++ b/test/e2e/virtual/apiexport/virtualworkspace_test.go @@ -37,6 +37,7 @@ import ( apierrors "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/api/meta" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" "k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/apimachinery/pkg/types" "k8s.io/apimachinery/pkg/util/sets" @@ -603,11 +604,11 @@ func TestAPIExportPermissionClaims(t *testing.T) { t.Logf("Bind sheriffs into %s and create initial sheriff", consumer1Path) apifixtures.BindToExport(ctx, t, sheriffProviderPath, "wild.wild.west", consumer1Path, kcpClusterClient) - apifixtures.CreateSheriff(ctx, t, dynamicClusterClient, consumer1Path, "wild.wild.west", "in-vw-before") + createSheriff(ctx, t, dynamicClusterClient, consumer1Path, "wild.wild.west", "in-vw-before") t.Logf("Bind sheriffs into %s and create initial sheriff", consumer2Path) apifixtures.BindToExport(ctx, t, sheriffProviderPath, "wild.wild.west", consumer2Path, kcpClusterClient) - apifixtures.CreateSheriff(ctx, t, dynamicClusterClient, consumer2Path, "wild.wild.west", "not-in-vw") + createSheriff(ctx, t, dynamicClusterClient, consumer2Path, "wild.wild.west", "not-in-vw") t.Logf("Create cowboys API Export in %v with permission claims to core resources and sheriffs provided by %v", claimerPath, sheriffProviderPath) setUpServiceProviderWithPermissionClaims(ctx, t, dynamicClusterClient, kcpClusterClient, claimerPath, cfg, identityHash) @@ -718,7 +719,7 @@ func TestAPIExportPermissionClaims(t *testing.T) { }, wait.ForeverTestTimeout, 100*time.Millisecond, "expected to see more than 1 binding") t.Logf("Creating a sheriff in %s", consumer1Path) - apifixtures.CreateSheriff(ctx, t, dynamicClusterClient, consumer1Path, "wild.wild.west", "in-vw") + createSheriff(ctx, t, dynamicClusterClient, consumer1Path, "wild.wild.west", "in-vw") t.Logf("Verify that two sherrifs are eventually returned") kcptestinghelpers.Eventually(t, func() (done bool, str string) { @@ -1188,3 +1189,32 @@ func toJSON(t *testing.T, obj interface{}) string { require.NoError(t, err) return string(ret) } + +func createSheriff( + ctx context.Context, + t *testing.T, + dynamicClusterClient kcpdynamic.ClusterInterface, + clusterName logicalcluster.Path, + group, name string, +) { + t.Helper() + + name = strings.ReplaceAll(name, ":", "-") + + t.Logf("Creating %s/v1 sheriffs %s|default/%s", group, clusterName, name) + + sheriffsGVR := schema.GroupVersionResource{Group: group, Resource: "sheriffs", Version: "v1"} + + sheriff := &unstructured.Unstructured{} + sheriff.SetAPIVersion(group + "/v1") + sheriff.SetKind("Sheriff") + sheriff.SetName(name) + + // CRDs are asynchronously served because they are informer based. + kcptestinghelpers.Eventually(t, func() (bool, string) { + if _, err := dynamicClusterClient.Cluster(clusterName).Resource(sheriffsGVR).Namespace("default").Create(ctx, sheriff, metav1.CreateOptions{}); err != nil { + return false, fmt.Sprintf("failed to create Sheriff %s|%s: %v", clusterName, name, err.Error()) + } + return true, "" + }, wait.ForeverTestTimeout, time.Millisecond*100, "error creating Sheriff %s|%s", clusterName, name) +} diff --git a/test/e2e/watchcache/watchcache_enabled_test.go b/test/e2e/watchcache/watchcache_enabled_test.go index 5da21334bb4..b5de7f49108 100644 --- a/test/e2e/watchcache/watchcache_enabled_test.go +++ b/test/e2e/watchcache/watchcache_enabled_test.go @@ -30,6 +30,7 @@ import ( v1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" "k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/apimachinery/pkg/util/wait" "k8s.io/client-go/rest" @@ -37,6 +38,7 @@ import ( kcpapiextensionsclientset "github.com/kcp-dev/client-go/apiextensions/client" kcpdynamic "github.com/kcp-dev/client-go/dynamic" kcpkubernetesclientset "github.com/kcp-dev/client-go/kubernetes" + "github.com/kcp-dev/logicalcluster/v3" "github.com/kcp-dev/sdk/apis/core" kcpclientset "github.com/kcp-dev/sdk/client/clientset/versioned/cluster" kcptesting "github.com/kcp-dev/sdk/testing" @@ -131,7 +133,7 @@ func TestWatchCacheEnabledForAPIBindings(t *testing.T) { apifixtures.CreateSheriffsSchemaAndExport(ctx, t, wsExport1aPath, kcpClusterClient, group, "export1") apifixtures.BindToExport(ctx, t, wsExport1aPath, group, wsConsume1aPath, kcpClusterClient) - apifixtures.CreateSheriff(ctx, t, dynamicKcpClusterClient, wsConsume1aPath, group, wsConsume1aPath.String()) + createSheriff(ctx, t, dynamicKcpClusterClient, wsConsume1aPath, group, wsConsume1aPath.String()) sheriffsGVR := schema.GroupVersionResource{Group: group, Resource: "sheriffs", Version: "v1"} t.Logf("Waiting until the watch cache is primed for %v for cluster %v", sheriffsGVR, wsConsume1aPath) @@ -259,3 +261,32 @@ func assertWatchCacheIsPrimed(t *testing.T, fn func() error) { return true, "" }, wait.ForeverTestTimeout, time.Millisecond*200, "the watch cache hasn't been primed in the allotted time") } + +func createSheriff( + ctx context.Context, + t *testing.T, + dynamicClusterClient kcpdynamic.ClusterInterface, + clusterName logicalcluster.Path, + group, name string, +) { + t.Helper() + + name = strings.ReplaceAll(name, ":", "-") + + t.Logf("Creating %s/v1 sheriffs %s|default/%s", group, clusterName, name) + + sheriffsGVR := schema.GroupVersionResource{Group: group, Resource: "sheriffs", Version: "v1"} + + sheriff := &unstructured.Unstructured{} + sheriff.SetAPIVersion(group + "/v1") + sheriff.SetKind("Sheriff") + sheriff.SetName(name) + + // CRDs are asynchronously served because they are informer based. + kcptestinghelpers.Eventually(t, func() (bool, string) { + if _, err := dynamicClusterClient.Cluster(clusterName).Resource(sheriffsGVR).Namespace("default").Create(ctx, sheriff, metav1.CreateOptions{}); err != nil { + return false, fmt.Sprintf("failed to create Sheriff %s|%s: %v", clusterName, name, err.Error()) + } + return true, "" + }, wait.ForeverTestTimeout, time.Millisecond*100, "error creating Sheriff %s|%s", clusterName, name) +}