@@ -5,17 +5,18 @@ import (
5
5
"flag"
6
6
"fmt"
7
7
"math/rand"
8
+ "strings"
8
9
"testing"
9
10
"time"
10
11
11
12
"github.com/google/go-cmp/cmp"
12
13
apierrors "k8s.io/apimachinery/pkg/api/errors"
13
14
14
15
kcpclienthelper "github.com/kcp-dev/apimachinery/pkg/client"
15
-
16
- apisv1alpha1 "github.com/kcp-dev/kcp/pkg /apis/apis /v1alpha1"
17
- tenancyv1alpha1 "github.com/kcp-dev/kcp/pkg /apis/tenancy/v1alpha1"
18
- "github.com/kcp-dev/kcp/pkg /apis/third_party/conditions/util/conditions"
16
+ apisv1alpha1 "github.com/kcp-dev/kcp/sdk/apis/apis/v1alpha1"
17
+ corev1alpha1 "github.com/kcp-dev/kcp/sdk /apis/core /v1alpha1"
18
+ tenancyv1alpha1 "github.com/kcp-dev/kcp/sdk /apis/tenancy/v1alpha1"
19
+ "github.com/kcp-dev/kcp/sdk /apis/third_party/conditions/util/conditions"
19
20
20
21
"github.com/kcp-dev/logicalcluster/v2"
21
22
@@ -35,11 +36,7 @@ import (
35
36
36
37
// The tests in this package expect to be called when:
37
38
// - kcp is running
38
- // - a kind cluster is up and running
39
- // - it is hosting a syncer, and the SyncTarget is ready to go
40
- // - the controller-manager from this repo is deployed to kcp
41
- // - that deployment is synced to the kind cluster
42
- // - the deployment is rolled out & ready
39
+ // - the controller-manager from this repo is running
43
40
//
44
41
// We can then check that the controllers defined here are working as expected.
45
42
@@ -51,7 +48,6 @@ func init() {
51
48
}
52
49
53
50
func parentWorkspace (t * testing.T ) logicalcluster.Name {
54
- flag .Parse ()
55
51
if workspaceName == "" {
56
52
t .Fatal ("--workspace cannot be empty" )
57
53
}
@@ -65,7 +61,7 @@ func loadClusterConfig(t *testing.T, clusterName logicalcluster.Name) *rest.Conf
65
61
if err != nil {
66
62
t .Fatalf ("failed to load *rest.Config: %v" , err )
67
63
}
68
- return rest .AddUserAgent (kcpclienthelper .ConfigWithCluster (restConfig , clusterName ), t .Name ())
64
+ return rest .AddUserAgent (kcpclienthelper .SetCluster (restConfig , clusterName ), t .Name ())
69
65
}
70
66
71
67
func loadClient (t * testing.T , clusterName logicalcluster.Name ) client.Client {
@@ -98,13 +94,13 @@ func createWorkspace(t *testing.T, clusterName logicalcluster.Name) client.Clien
98
94
}
99
95
c := loadClient (t , parent )
100
96
t .Logf ("creating workspace %s" , clusterName )
101
- if err := c .Create (context .TODO (), & tenancyv1alpha1.ClusterWorkspace {
97
+ if err := c .Create (context .TODO (), & tenancyv1alpha1.Workspace {
102
98
ObjectMeta : metav1.ObjectMeta {
103
99
Name : clusterName .Base (),
104
100
},
105
- Spec : tenancyv1alpha1.ClusterWorkspaceSpec {
106
- Type : tenancyv1alpha1.ClusterWorkspaceTypeReference {
107
- Name : "universal " ,
101
+ Spec : tenancyv1alpha1.WorkspaceSpec {
102
+ Type : tenancyv1alpha1.WorkspaceTypeReference {
103
+ Name : "widgets " ,
108
104
Path : "root" ,
109
105
},
110
106
},
@@ -113,15 +109,15 @@ func createWorkspace(t *testing.T, clusterName logicalcluster.Name) client.Clien
113
109
}
114
110
115
111
t .Logf ("waiting for workspace %s to be ready" , clusterName )
116
- var workspace tenancyv1alpha1.ClusterWorkspace
112
+ var workspace tenancyv1alpha1.Workspace
117
113
if err := wait .PollImmediate (100 * time .Millisecond , wait .ForeverTestTimeout , func () (done bool , err error ) {
118
114
fetchErr := c .Get (context .TODO (), client.ObjectKey {Name : clusterName .Base ()}, & workspace )
119
115
if fetchErr != nil {
120
116
t .Logf ("failed to get workspace %s: %v" , clusterName , err )
121
117
return false , fetchErr
122
118
}
123
119
var reason string
124
- if actual , expected := workspace .Status .Phase , tenancyv1alpha1 . ClusterWorkspacePhaseReady ; actual != expected {
120
+ if actual , expected := workspace .Status .Phase , corev1alpha1 . LogicalClusterPhaseReady ; actual != expected {
125
121
reason = fmt .Sprintf ("phase is %s, not %s" , actual , expected )
126
122
t .Logf ("not done waiting for workspace %s to be ready: %s" , clusterName , reason )
127
123
}
@@ -130,32 +126,26 @@ func createWorkspace(t *testing.T, clusterName logicalcluster.Name) client.Clien
130
126
t .Fatalf ("workspace %s never ready: %v" , clusterName , err )
131
127
}
132
128
133
- return createAPIBinding (t , clusterName )
129
+ return waitingForAPIBinding (t , clusterName )
134
130
}
135
131
136
- func createAPIBinding (t * testing.T , workspaceCluster logicalcluster.Name ) client.Client {
132
+ func waitingForAPIBinding (t * testing.T , workspaceCluster logicalcluster.Name ) client.Client {
137
133
c := loadClient (t , workspaceCluster )
138
- apiName := "controller-runtime-example-data.my.domain"
139
- t .Logf ("creating APIBinding %s|%s" , workspaceCluster , apiName )
140
- if err := c .Create (context .TODO (), & apisv1alpha1.APIBinding {
141
- ObjectMeta : metav1.ObjectMeta {
142
- Name : apiName ,
143
- },
144
- Spec : apisv1alpha1.APIBindingSpec {
145
- Reference : apisv1alpha1.ExportReference {
146
- Workspace : & apisv1alpha1.WorkspaceExportReference {
147
- Path : parentWorkspace (t ).String (),
148
- ExportName : apiName ,
149
- },
150
- },
151
- AcceptedPermissionClaims : []apisv1alpha1.PermissionClaim {
152
- {GroupResource : apisv1alpha1.GroupResource {Resource : "configmaps" }},
153
- {GroupResource : apisv1alpha1.GroupResource {Resource : "secrets" }},
154
- {GroupResource : apisv1alpha1.GroupResource {Resource : "namespaces" }},
155
- },
156
- },
157
- }); err != nil {
158
- t .Fatalf ("could not create APIBinding %s|%s: %v" , workspaceCluster , apiName , err )
134
+ ctx := context .TODO ()
135
+ apiNamePrefix := "data.my.domain" // matches bootstrapped name
136
+
137
+ list := & apisv1alpha1.APIBindingList {}
138
+ err := c .List (ctx , list )
139
+ if err != nil {
140
+ t .Fatalf ("failed to list APIBindings: %v" , err )
141
+ }
142
+
143
+ apiName := ""
144
+ for _ , apiBinding := range list .Items {
145
+ if strings .HasPrefix (apiBinding .Name , apiNamePrefix ) {
146
+ apiName = apiBinding .Name
147
+ break
148
+ }
159
149
}
160
150
161
151
t .Logf ("waiting for APIBinding %s|%s to be bound" , workspaceCluster , apiName )
0 commit comments