Skip to content
Open
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
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 ?=
Expand All @@ -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
Expand Down
1 change: 0 additions & 1 deletion pkg/network/dialer_linux.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//go:build linux
// +build linux

/*
Copyright 2024 The KCP Authors.
Expand Down
1 change: 0 additions & 1 deletion pkg/network/dialer_other.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//go:build !linux
// +build !linux

/*
Copyright 2024 The KCP Authors.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
42 changes: 37 additions & 5 deletions test/e2e/conformance/cross_logical_cluster_list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package conformance
import (
"context"
"fmt"
"strings"
"testing"
"time"

Expand All @@ -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"
Expand All @@ -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"
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
}
1 change: 1 addition & 0 deletions test/e2e/fixtures/apifixtures/sheriffs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
52 changes: 38 additions & 14 deletions test/e2e/quota/quota_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package quota
import (
"context"
"fmt"
"strings"
"testing"
"time"

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
}
36 changes: 33 additions & 3 deletions test/e2e/virtual/apiexport/virtualworkspace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
}
33 changes: 32 additions & 1 deletion test/e2e/watchcache/watchcache_enabled_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,15 @@ 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"

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"
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
}