Skip to content

Commit 4af23e3

Browse files
authored
Merge pull request kubernetes-sigs#9461 from Ankitasw/add-import-restrictions
🌱 Enforce import restrictions in all API packages
2 parents 21d3c7b + 615b5e6 commit 4af23e3

35 files changed

+169
-37
lines changed

bootstrap/kubeadm/api/v1alpha4/groupversion_info.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ var (
3737

3838
objectTypes = []runtime.Object{}
3939

40+
// localSchemeBuilder is used for type conversions.
4041
localSchemeBuilder = schemeBuilder
4142
)
4243

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
rules:
2+
- selectorRegexp: sigs[.]k8s[.]io/controller-runtime
3+
allowedPrefixes: []
4+
forbiddenPrefixes:
5+
- "sigs.k8s.io/controller-runtime"

cmd/clusterctl/internal/test/providers/controlplane/generic_types.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,5 @@ type GenericControlPlaneList struct {
5050
}
5151

5252
func init() {
53-
SchemeBuilder.Register(
54-
&GenericControlPlane{}, &GenericControlPlaneList{},
55-
)
53+
objectTypes = append(objectTypes, &GenericControlPlane{}, &GenericControlPlaneList{})
5654
}

cmd/clusterctl/internal/test/providers/controlplane/groupversion_info.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,25 @@ limitations under the License.
2020
package controlplane
2121

2222
import (
23+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
24+
"k8s.io/apimachinery/pkg/runtime"
2325
"k8s.io/apimachinery/pkg/runtime/schema"
24-
"sigs.k8s.io/controller-runtime/pkg/scheme"
2526
)
2627

2728
var (
2829
// GroupVersion is group version used to register these objects.
2930
GroupVersion = schema.GroupVersion{Group: "controlplane.cluster.x-k8s.io", Version: "v1beta1"}
3031

31-
// SchemeBuilder is used to add go types to the GroupVersionKind scheme.
32-
SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion}
32+
schemeBuilder = runtime.NewSchemeBuilder(addKnownTypes)
3333

3434
// AddToScheme adds the types in this group-version to the given scheme.
35-
AddToScheme = SchemeBuilder.AddToScheme
35+
AddToScheme = schemeBuilder.AddToScheme
36+
37+
objectTypes = []runtime.Object{}
3638
)
39+
40+
func addKnownTypes(scheme *runtime.Scheme) error {
41+
scheme.AddKnownTypes(GroupVersion, objectTypes...)
42+
metav1.AddToGroupVersion(scheme, GroupVersion)
43+
return nil
44+
}

cmd/clusterctl/internal/test/providers/controlplane/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.

controlplane/kubeadm/api/v1alpha4/groupversion_info.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,10 @@ var (
3535
// AddToScheme adds the types in this group-version to the given scheme.
3636
AddToScheme = schemeBuilder.AddToScheme
3737

38-
localSchemeBuilder = schemeBuilder
39-
4038
objectTypes = []runtime.Object{}
39+
40+
// localSchemeBuilder is used for type conversions.
41+
localSchemeBuilder = schemeBuilder
4142
)
4243

4344
func addKnownTypes(scheme *runtime.Scheme) error {

exp/addons/api/.import-restrictions

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
rules:
2+
- selectorRegexp: sigs[.]k8s[.]io/controller-runtime
3+
allowedPrefixes:
4+
- "sigs.k8s.io/controller-runtime/pkg/conversion"
5+
forbiddenPrefixes: []

exp/addons/api/v1alpha4/clusterresourceset_types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,5 +141,5 @@ type ClusterResourceSetList struct {
141141
}
142142

143143
func init() {
144-
SchemeBuilder.Register(&ClusterResourceSet{}, &ClusterResourceSetList{})
144+
objectTypes = append(objectTypes, &ClusterResourceSet{}, &ClusterResourceSetList{})
145145
}

exp/addons/api/v1alpha4/clusterresourcesetbinding_types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,5 +138,5 @@ type ClusterResourceSetBindingList struct {
138138
}
139139

140140
func init() {
141-
SchemeBuilder.Register(&ClusterResourceSetBinding{}, &ClusterResourceSetBindingList{})
141+
objectTypes = append(objectTypes, &ClusterResourceSetBinding{}, &ClusterResourceSetBindingList{})
142142
}

exp/addons/api/v1alpha4/groupversion_info.go

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,28 @@ limitations under the License.
2020
package v1alpha4
2121

2222
import (
23+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
24+
"k8s.io/apimachinery/pkg/runtime"
2325
"k8s.io/apimachinery/pkg/runtime/schema"
24-
"sigs.k8s.io/controller-runtime/pkg/scheme"
2526
)
2627

2728
var (
2829
// GroupVersion is group version used to register these objects.
2930
GroupVersion = schema.GroupVersion{Group: "addons.cluster.x-k8s.io", Version: "v1alpha4"}
3031

31-
// SchemeBuilder is used to add go types to the GroupVersionKind scheme.
32-
SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion}
32+
schemeBuilder = runtime.NewSchemeBuilder(addKnownTypes)
3333

3434
// AddToScheme adds the types in this group-version to the given scheme.
35-
AddToScheme = SchemeBuilder.AddToScheme
35+
AddToScheme = schemeBuilder.AddToScheme
3636

37-
localSchemeBuilder = SchemeBuilder.SchemeBuilder
37+
objectTypes = []runtime.Object{}
38+
39+
// localSchemeBuilder is used for type conversions.
40+
localSchemeBuilder = schemeBuilder
3841
)
42+
43+
func addKnownTypes(scheme *runtime.Scheme) error {
44+
scheme.AddKnownTypes(GroupVersion, objectTypes...)
45+
metav1.AddToGroupVersion(scheme, GroupVersion)
46+
return nil
47+
}

0 commit comments

Comments
 (0)