Skip to content

Commit d51e65c

Browse files
authored
feat: Migrate provider-template from cluster scope to namespaced scope (#132)
This PR migrates the provider template from Crossplane v1 to v2. It also implements Gate feature that introduced from v2 to control resources to install to the cluster. Key changes: API Updates: - Consolidate ProviderConfig and related types into unified types.go - Add namespaced ProviderConfig alongside cluster-scoped ClusterProviderConfig - Add namespaced ProviderConfigUsage and ClusterProviderConfigUsage - Update MyType to use namespaced scope by default - Remove deprecated StoreConfig (external secret stores no longer supported in v2) - Migrate to crossplane-runtime v2.0.0 with breaking changes Controller Enhancements: - Implement safe-start pattern with SetupGated functions - Add gate-based controller registration to wait for CRDs - Add customresourcesgate controller to watch for CRD availability - Update credential extraction to support both namespaced and cluster-scoped configs - Support dynamic ProviderConfig reference kind switching - Remove deprecated feature flag system in favor of runtime feature package - Remove deprecated non-gated Setup function from register.go - Rename internal/controller/template.go to register.go for clarity Template Updates: - Add SetupGated function to controller template for safe-start support - Update controller template to use v1alpha1 instead of dynamic API version - Fix typo: WithExternalConnecter -> WithExternalConnector - Remove unused ConnectionPublisher initialization - Add missing xpv1 import for ResourceStatus in type templates - Change Status to use xpv1.ResourceStatus instead of xpv2.ResourceStatus - Improve error constant alignment and formatting Dependencies: - Upgrade to crossplane-runtime v2.0.0 - Add k8s.io/apiextensions-apiserver for CRD scheme registration - Update controller-runtime to v0.21.0 - Update Go toolchain to 1.24.5 Examples and Documentation: - Update code generation templates for namespaced resources - Add namespace field to example manifests - Update ProviderConfig examples to demonstrate new structure - Remove StoreConfig examples - Update README.md to include step for registering new types in SetupGated - Fix capitalization: "Template provider" -> "template provider" - Fix capitalization: "group Sample" -> "group sample" Package Metadata: - Add safe-start capability to crossplane.yaml package metadata This migration provides better resource isolation, simplified authentication patterns, and improved startup reliability through the safe-start mechanism. Signed-off-by: Chuan-Yen Chiang <[email protected]>
1 parent 529bc62 commit d51e65c

40 files changed

+1059
-1103
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ with the following features that are meant to be refactored:
2727
5. Replace the *sample* group with your new group in apis/{provider}.go
2828
5. Replace the *mytype* type with your new type in internal/controller/{provider}.go
2929
5. Replace the default controller and ProviderConfig implementations with your own
30+
5. Register your new type into `SetupGated` function in `internal/controller/register.go`
3031
5. Run `make reviewable` to run code generation, linters, and tests.
3132
5. Run `make build` to build the provider.
3233

apis/generate.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
//go:build generate
2-
31
/*
42
Copyright 2025 The Crossplane Authors.
53
@@ -29,9 +27,3 @@ limitations under the License.
2927
//go:generate go run -tags generate github.com/crossplane/crossplane-tools/cmd/angryjet generate-methodsets --header-file=../hack/boilerplate.go.txt ./...
3028

3129
package apis
32-
33-
import (
34-
_ "sigs.k8s.io/controller-tools/cmd/controller-gen" //nolint:typecheck
35-
36-
_ "github.com/crossplane/crossplane-tools/cmd/angryjet" //nolint:typecheck
37-
)

apis/sample/sample.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
// Package sample contains group Sample API versions
17+
// Package sample contains group sample API versions
1818
package sample

apis/sample/v1alpha1/groupversion_info.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
// Package v1alpha1 contains the v1alpha1 group Sample resources of the Template provider.
17+
// Package v1alpha1 contains the v1alpha1 group Sample resources of the template provider.
1818
// +kubebuilder:object:generate=true
1919
// +groupName=sample.template.crossplane.io
2020
// +versionName=v1alpha1

apis/sample/v1alpha1/mytype_types.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ import (
2222
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2323
"k8s.io/apimachinery/pkg/runtime/schema"
2424

25-
xpv1 "github.com/crossplane/crossplane-runtime/apis/common/v1"
25+
xpv1 "github.com/crossplane/crossplane-runtime/v2/apis/common/v1"
26+
xpv2 "github.com/crossplane/crossplane-runtime/v2/apis/common/v2"
2627
)
2728

2829
// MyTypeParameters are the configurable fields of a MyType.
@@ -38,8 +39,8 @@ type MyTypeObservation struct {
3839

3940
// A MyTypeSpec defines the desired state of a MyType.
4041
type MyTypeSpec struct {
41-
xpv1.ResourceSpec `json:",inline"`
42-
ForProvider MyTypeParameters `json:"forProvider"`
42+
xpv2.ManagedResourceSpec `json:",inline"`
43+
ForProvider MyTypeParameters `json:"forProvider"`
4344
}
4445

4546
// A MyTypeStatus represents the observed state of a MyType.
@@ -56,7 +57,7 @@ type MyTypeStatus struct {
5657
// +kubebuilder:printcolumn:name="EXTERNAL-NAME",type="string",JSONPath=".metadata.annotations.crossplane\\.io/external-name"
5758
// +kubebuilder:printcolumn:name="AGE",type="date",JSONPath=".metadata.creationTimestamp"
5859
// +kubebuilder:subresource:status
59-
// +kubebuilder:resource:scope=Cluster,categories={crossplane,managed,template}
60+
// +kubebuilder:resource:scope=Namespaced,categories={crossplane,managed,template}
6061
type MyType struct {
6162
metav1.TypeMeta `json:",inline"`
6263
metav1.ObjectMeta `json:"metadata,omitempty"`

apis/sample/v1alpha1/zz_generated.deepcopy.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apis/sample/v1alpha1/zz_generated.managed.go

Lines changed: 5 additions & 25 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apis/sample/v1alpha1/zz_generated.managedlist.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apis/v1alpha1/doc.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,8 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17+
// Package v1alpha1 contains the core resources of the Template provider.
18+
// +kubebuilder:object:generate=true
19+
// +groupName=template.crossplane.io
20+
// +versionName=v1alpha1
1721
package v1alpha1

apis/v1alpha1/groupversion_info.go

Lines changed: 0 additions & 40 deletions
This file was deleted.

0 commit comments

Comments
 (0)