Skip to content
This repository was archived by the owner on Apr 24, 2024. It is now read-only.

Commit 32255ed

Browse files
Merge pull request #36 from vincepri/update-kcp-011
Update example to work against latest kcp main (next 0.11)
2 parents f227021 + 0e26b6b commit 32255ed

17 files changed

+315
-247
lines changed

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Build the manager binary
2-
FROM golang:1.17 as builder
2+
FROM golang:1.18 as builder
33

44
WORKDIR /workspace
55
# Copy the Go Modules manifests

Makefile

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ YQ ?= $(LOCALBIN)/yq
3131
## Tool Versions
3232
KUSTOMIZE_VERSION ?= v3.8.7
3333
CONTROLLER_TOOLS_VERSION ?= v0.8.0
34-
KCP_VERSION ?= 0.9.1
34+
KCP_VERSION ?= 0.11.0-alpha.0
3535
YQ_VERSION ?= v4.27.2
3636

3737
KUSTOMIZE_INSTALL_SCRIPT ?= "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh"
@@ -123,14 +123,18 @@ test-e2e: $(ARTIFACT_DIR)/kind.kubeconfig kcp-synctarget ready-deployment run-te
123123

124124
.PHONY: run-test-e2e
125125
run-test-e2e: ## Run end-to-end tests on a cluster.
126-
go test ./test/e2e/... --kubeconfig $(abspath $(ARTIFACT_DIR)/kcp.kubeconfig) --workspace $(shell $(KCP_KUBECTL) kcp workspace . --short)
126+
go test -v ./test/e2e/... --kubeconfig $(abspath $(ARTIFACT_DIR)/kcp.kubeconfig) --workspace $(shell $(KCP_KUBECTL) get logicalcluster cluster -o jsonpath="{.metadata.annotations.kcp\.io/path}")
127127

128128
.PHONY: ready-deployment
129129
ready-deployment: KUBECONFIG = $(ARTIFACT_DIR)/kcp.kubeconfig
130-
ready-deployment: kind-image install deploy apibinding ## Deploy the controller-manager and wait for it to be ready.
130+
ready-deployment: kind-image install bindcompute deploy apibinding ## Deploy the controller-manager and wait for it to be ready.
131131
$(KCP_KUBECTL) --namespace "controller-runtime-example-system" rollout status deployment/controller-runtime-example-controller-manager
132132

133-
# TODO(skuznets|ncdc): this APIBinding is not needed, but here only to work around https://github.com/kcp-dev/kcp/issues/1183 - remove it once that is fixed
133+
.PHONY: bindcompute
134+
bindcompute:
135+
$(KCP_KUBECTL) kcp bind compute $(shell $(KCP_KUBECTL) get logicalcluster cluster -o jsonpath="{.metadata.annotations.kcp\.io/path}")
136+
137+
# TODO(skuznets|ncdc): this APIBinding is not needed, but here only to work around https://github.com/kcp-dev/kcp/issues/2663 - remove it once that is fixed
134138
.PHONY: apibinding
135139
apibinding:
136140
$( eval WORKSPACE = $(shell $(KCP_KUBECTL) kcp workspace . --short))
@@ -184,6 +188,10 @@ test-e2e-cleanup: ## Clean up processes and directories from an end-to-end test
184188
pkill -sigterm kcp || true
185189
pkill -sigterm kubectl || true
186190

191+
.PHONY: clean-bins
192+
clean-bins: ## Remove binaries.
193+
rm -rf $(ARTIFACT_DIR) || true
194+
187195
##@ Build
188196

189197
.PHONY: build

config/default/kustomization.yaml

Lines changed: 41 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ namePrefix: controller-runtime-example-
1313
# someName: someValue
1414

1515
bases:
16-
- ../kcp
17-
- ../rbac
18-
- ../manager
16+
- ../kcp
17+
- ../rbac
18+
- ../manager
1919
# [WEBHOOK] To enable webhook, uncomment all the sections with [WEBHOOK] prefix including the one in
2020
# crd/kustomization.yaml
2121
#- ../webhook
@@ -25,10 +25,10 @@ bases:
2525
#- ../prometheus
2626

2727
patchesStrategicMerge:
28-
# Protect the /metrics endpoint by putting it behind auth.
29-
# If you want your controller-manager to expose the /metrics
30-
# endpoint w/o any authn/z, please comment the following line.
31-
- manager_auth_proxy_patch.yaml
28+
# Protect the /metrics endpoint by putting it behind auth.
29+
# If you want your controller-manager to expose the /metrics
30+
# endpoint w/o any authn/z, please comment the following line.
31+
- manager_auth_proxy_patch.yaml
3232

3333
# Mount the controller config file for loading manager configurations
3434
# through a ComponentConfig type
@@ -45,37 +45,37 @@ patchesStrategicMerge:
4545

4646
# the following config is for teaching kustomize how to do var substitution
4747
vars:
48-
# [CERTMANAGER] To enable cert-manager, uncomment all sections with 'CERTMANAGER' prefix.
49-
#- name: CERTIFICATE_NAMESPACE # namespace of the certificate CR
50-
# objref:
51-
# kind: Certificate
52-
# group: cert-manager.io
53-
# version: v1
54-
# name: serving-cert # this name should match the one in certificate.yaml
55-
# fieldref:
56-
# fieldpath: metadata.namespace
57-
#- name: CERTIFICATE_NAME
58-
# objref:
59-
# kind: Certificate
60-
# group: cert-manager.io
61-
# version: v1
62-
# name: serving-cert # this name should match the one in certificate.yaml
63-
#- name: SERVICE_NAMESPACE # namespace of the service
64-
# objref:
65-
# kind: Service
66-
# version: v1
67-
# name: webhook-service
68-
# fieldref:
69-
# fieldpath: metadata.namespace
70-
#- name: SERVICE_NAME
71-
# objref:
72-
# kind: Service
73-
# version: v1
74-
# name: webhook-service
75-
- name: API_EXPORT_NAME
76-
objref:
77-
apiVersion: apis.kcp.dev/v1alpha1
78-
kind: APIExport
79-
name: data.my.domain
80-
fieldref:
81-
fieldPath: metadata.name
48+
# [CERTMANAGER] To enable cert-manager, uncomment all sections with 'CERTMANAGER' prefix.
49+
#- name: CERTIFICATE_NAMESPACE # namespace of the certificate CR
50+
# objref:
51+
# kind: Certificate
52+
# group: cert-manager.io
53+
# version: v1
54+
# name: serving-cert # this name should match the one in certificate.yaml
55+
# fieldref:
56+
# fieldpath: metadata.namespace
57+
#- name: CERTIFICATE_NAME
58+
# objref:
59+
# kind: Certificate
60+
# group: cert-manager.io
61+
# version: v1
62+
# name: serving-cert # this name should match the one in certificate.yaml
63+
#- name: SERVICE_NAMESPACE # namespace of the service
64+
# objref:
65+
# kind: Service
66+
# version: v1
67+
# name: webhook-service
68+
# fieldref:
69+
# fieldpath: metadata.namespace
70+
#- name: SERVICE_NAME
71+
# objref:
72+
# kind: Service
73+
# version: v1
74+
# name: webhook-service
75+
- name: API_EXPORT_NAME
76+
objref:
77+
apiVersion: apis.kcp.io/v1alpha1
78+
kind: APIExport
79+
name: data.my.domain
80+
fieldref:
81+
fieldPath: metadata.name

config/kcp/apiexport.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
apiVersion: apis.kcp.dev/v1alpha1
1+
apiVersion: apis.kcp.io/v1alpha1
22
kind: APIExport
33
metadata:
44
name: data.my.domain
@@ -8,7 +8,10 @@ spec:
88
permissionClaims:
99
- group: ""
1010
resource: "secrets"
11+
all: true
1112
- group: ""
1213
resource: "configmaps"
14+
all: true
1315
- group: ""
1416
resource: "namespaces"
17+
all: true

config/kcp/clusterrole.yaml

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,17 @@ metadata:
55
creationTimestamp: null
66
name: kcp-manager-role
77
rules:
8-
- apiGroups:
9-
- apis.kcp.dev
10-
resources:
11-
- apiexports
12-
verbs:
13-
- get
14-
- list
15-
- watch
16-
- apiGroups:
17-
- apis.kcp.dev
18-
resources:
19-
- apiexports/content
20-
verbs:
21-
- '*'
8+
- apiGroups:
9+
- apis.kcp.io
10+
resources:
11+
- apiexports
12+
verbs:
13+
- get
14+
- list
15+
- watch
16+
- apiGroups:
17+
- apis.kcp.io
18+
resources:
19+
- apiexports/content
20+
verbs:
21+
- "*"
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
apiVersion: rbac.authorization.k8s.io/v1
2+
kind: ClusterRole
3+
metadata:
4+
name: controller-runtime-example
5+
rules:
6+
- apiGroups: ["apis.kcp.io"]
7+
resources:
8+
- "apiexports"
9+
resourceNames:
10+
- "data.my.domain"
11+
verbs: ["bind"]
12+
---
13+
apiVersion: rbac.authorization.k8s.io/v1
14+
kind: ClusterRoleBinding
15+
metadata:
16+
name: controller-runtime-example
17+
roleRef:
18+
apiGroup: rbac.authorization.k8s.io
19+
kind: ClusterRole
20+
name: controller-runtime-example
21+
subjects:
22+
- apiGroup: rbac.authorization.k8s.io
23+
kind: Group
24+
name: system:authenticated

config/kcp/kustomization.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ resources:
33
- apiexport.yaml
44
- clusterrole.yaml
55
- clusterrolebinding.yaml
6+
- clusterroles-apiexport-bind.yaml
67

78
configurations:
89
- kustomizeconfig.yaml

config/kcp/kustomizeconfig.yaml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
nameReference:
2-
- kind: APIResourceSchema
3-
fieldSpecs:
2+
- kind: APIResourceSchema
3+
fieldSpecs:
4+
- kind: APIExport
5+
path: spec/latestResourceSchemas
46
- kind: APIExport
5-
path: spec/latestResourceSchemas
7+
fieldSpecs:
8+
- kind: ClusterRole
9+
path: rules/resourceNames
Lines changed: 37 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
apiVersion: apis.kcp.dev/v1alpha1
1+
apiVersion: apis.kcp.io/v1alpha1
22
kind: APIResourceSchema
33
metadata:
44
creationTimestamp: null
@@ -12,38 +12,41 @@ spec:
1212
singular: widget
1313
scope: Namespaced
1414
versions:
15-
- name: v1alpha1
16-
schema:
17-
description: Widget is the Schema for the widgets API
18-
properties:
19-
apiVersion:
20-
description: 'APIVersion defines the versioned schema of this representation
21-
of an object. Servers should convert recognized schemas to the latest
22-
internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
23-
type: string
24-
kind:
25-
description: 'Kind is a string value representing the REST resource this
26-
object represents. Servers may infer this from the endpoint the client
27-
submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
28-
type: string
29-
metadata:
30-
type: object
31-
spec:
32-
description: WidgetSpec defines the desired state of Widget
33-
properties:
34-
foo:
35-
type: string
36-
type: object
37-
status:
38-
description: WidgetStatus defines the observed state of Widget
39-
properties:
40-
total:
41-
type: integer
42-
type: object
43-
type: object
44-
served: true
45-
storage: true
46-
subresources:
47-
status: {}
15+
- name: v1alpha1
16+
schema:
17+
description: Widget is the Schema for the widgets API
18+
properties:
19+
apiVersion:
20+
description:
21+
"APIVersion defines the versioned schema of this representation
22+
of an object. Servers should convert recognized schemas to the latest
23+
internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources"
24+
type: string
25+
kind:
26+
description:
27+
"Kind is a string value representing the REST resource this
28+
object represents. Servers may infer this from the endpoint the client
29+
submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds"
30+
type: string
31+
metadata:
32+
type: object
33+
spec:
34+
description: WidgetSpec defines the desired state of Widget
35+
properties:
36+
foo:
37+
type: string
38+
type: object
39+
status:
40+
description: WidgetStatus defines the observed state of Widget
41+
properties:
42+
total:
43+
type: integer
44+
type: object
45+
type: object
46+
served: true
47+
storage: true
48+
subresources:
49+
status: {}
4850

4951
---
52+

config/rbac/role.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ rules:
8484
- patch
8585
- update
8686
- apiGroups:
87-
- apis.kcp.dev
87+
- apis.kcp.io
8888
resources:
8989
- apiexports
9090
verbs:

controllers/configmap_controller.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ import (
2626
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2727
"k8s.io/apimachinery/pkg/types"
2828

29-
"github.com/kcp-dev/logicalcluster/v2"
30-
29+
"github.com/kcp-dev/logicalcluster/v3"
3130
ctrl "sigs.k8s.io/controller-runtime"
3231
"sigs.k8s.io/controller-runtime/pkg/client"
3332
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
33+
"sigs.k8s.io/controller-runtime/pkg/kontext"
3434
"sigs.k8s.io/controller-runtime/pkg/log"
3535
)
3636

@@ -53,7 +53,7 @@ type ConfigMapReconciler struct {
5353
func (r *ConfigMapReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
5454
log := log.FromContext(ctx).WithValues("cluster", req.ClusterName)
5555

56-
ctx = logicalcluster.WithCluster(ctx, logicalcluster.New(req.ClusterName))
56+
ctx = kontext.WithCluster(ctx, logicalcluster.Name(req.ClusterName))
5757

5858
// Test get
5959
var configMap corev1.ConfigMap
@@ -135,7 +135,7 @@ func (r *ConfigMapReconciler) Reconcile(ctx context.Context, req ctrl.Request) (
135135

136136
secret.SetName(configMap.GetName())
137137
secret.SetNamespace(configMap.GetNamespace())
138-
secret.SetOwnerReferences([]metav1.OwnerReference{metav1.OwnerReference{
138+
secret.SetOwnerReferences([]metav1.OwnerReference{{
139139
Name: configMap.GetName(),
140140
UID: configMap.GetUID(),
141141
APIVersion: "v1",

controllers/widget_controller.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,12 @@ package controllers
1919
import (
2020
"context"
2121

22-
"github.com/kcp-dev/logicalcluster/v2"
22+
"github.com/kcp-dev/logicalcluster/v3"
2323
"k8s.io/apimachinery/pkg/api/errors"
2424
"k8s.io/apimachinery/pkg/runtime"
2525
ctrl "sigs.k8s.io/controller-runtime"
2626
"sigs.k8s.io/controller-runtime/pkg/client"
27+
"sigs.k8s.io/controller-runtime/pkg/kontext"
2728
"sigs.k8s.io/controller-runtime/pkg/log"
2829

2930
datav1alpha1 "github.com/kcp-dev/controller-runtime-example/api/v1alpha1"
@@ -56,7 +57,7 @@ func (r *WidgetReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctr
5657
logger.Info("Listed all widgets across all workspaces", "count", len(allWidgets.Items))
5758

5859
// Add the logical cluster to the context
59-
ctx = logicalcluster.WithCluster(ctx, logicalcluster.New(req.ClusterName))
60+
ctx = kontext.WithCluster(ctx, logicalcluster.Name(req.ClusterName))
6061

6162
logger.Info("Getting widget")
6263
var w datav1alpha1.Widget

0 commit comments

Comments
 (0)