@@ -24,15 +24,20 @@ import (
2424// +kubebuilder:resource:path=providers,scope=Namespaced,categories=cluster-api
2525// +kubebuilder:storageversion
2626// +kubebuilder:object:root=true
27- // +kubebuilder:printcolumn:name="Type",type="string",JSONPath=".type"
27+ // +kubebuilder:printcolumn:name="Type",type="string",JSONPath=".provider"
28+ // +kubebuilder:printcolumn:name="Provider",type="string",JSONPath=".type"
2829// +kubebuilder:printcolumn:name="Version",type="string",JSONPath=".version"
2930// +kubebuilder:printcolumn:name="Watch Namespace",type="string",JSONPath=".watchedNamespace"
3031
31- // Provider is the Schema for the providers API
32+ // Provider defines an entry in the provider inventory.
3233type Provider struct {
3334 metav1.TypeMeta `json:",inline"`
3435 metav1.ObjectMeta `json:"metadata,omitempty"`
3536
37+ // Provider indicates the name of the provider.
38+ // +optional
39+ Provider string `json:"provider,omitempty"`
40+
3641 // Type indicates the type of the provider.
3742 // See ProviderType for a list of supported values
3843 // +optional
@@ -48,7 +53,57 @@ type Provider struct {
4853 WatchedNamespace string `json:"watchedNamespace,omitempty"`
4954}
5055
51- // ProviderType is a string representation of a TaskGroup create policy.
56+ // ManifestLabel returns the cluster.x-k8s.io/provider label value for an entry in the provider inventory.
57+ // Please note that this label uniquely identifies the provider, e.g. bootstrap-kubeadm, but not the instances of
58+ // the provider, e.g. namespace-1/bootstrap-kubeadm and namespace-2/bootstrap-kubeadm
59+ func (p * Provider ) ManifestLabel () string {
60+ return ManifestLabel (p .Provider , p .GetProviderType ())
61+ }
62+
63+ // InstanceName return the a name that uniquely identifies an entry in the provider inventory.
64+ // The instanceName is composed by the ManifestLabel and by the namespace where the provider is installed;
65+ // the resulting value uniquely identify a provider instance because clusterctl does not support multiple
66+ //instances of the same provider to be installed in the same namespace.
67+ func (p * Provider ) InstanceName () string {
68+ return types.NamespacedName {Namespace : p .Namespace , Name : p .ManifestLabel ()}.String ()
69+ }
70+
71+ // HasWatchingOverlapWith returns true if the provider has an overlapping watching namespace with another provider.
72+ func (p * Provider ) HasWatchingOverlapWith (other Provider ) bool {
73+ return p .WatchedNamespace == "" || p .WatchedNamespace == other .WatchedNamespace || other .WatchedNamespace == ""
74+ }
75+
76+ // SameAs returns true if two providers have the same Provider and type.
77+ // Please note that there could be many instances of the same provider.
78+ func (p * Provider ) SameAs (other Provider ) bool {
79+ return p .Provider == other .Provider && p .Type == other .Type
80+ }
81+
82+ // Equals returns true if two providers are identical (same name, type, version etc.).
83+ func (p * Provider ) Equals (other Provider ) bool {
84+ return p .Name == other .Name &&
85+ p .Namespace == other .Namespace &&
86+ p .Provider == other .Provider &&
87+ p .Type == other .Type &&
88+ p .WatchedNamespace == other .WatchedNamespace &&
89+ p .Version == other .Version
90+ }
91+
92+ // GetProviderType parse the Provider.Type string field and return the typed representation.
93+ func (p * Provider ) GetProviderType () ProviderType {
94+ switch t := ProviderType (p .Type ); t {
95+ case
96+ CoreProviderType ,
97+ BootstrapProviderType ,
98+ InfrastructureProviderType ,
99+ ControlPlaneProviderType :
100+ return t
101+ default :
102+ return ProviderTypeUnknown
103+ }
104+ }
105+
106+ // ProviderType is a string representation of a Provider type..
52107type ProviderType string
53108
54109const (
@@ -68,42 +123,22 @@ const (
68123 ProviderTypeUnknown = ProviderType ("" )
69124)
70125
71- // GetProviderType attempts to parse the ProviderType field and return
72- // the typed ProviderType representation.
73- func (p * Provider ) GetProviderType () ProviderType {
74- switch t := ProviderType (p .Type ); t {
75- case
76- CoreProviderType ,
77- BootstrapProviderType ,
78- InfrastructureProviderType ,
79- ControlPlaneProviderType :
80- return t
126+ // Order return an integer that can be used to sort ProviderType values.
127+ func (p ProviderType ) Order () int {
128+ switch p {
129+ case CoreProviderType :
130+ return 0
131+ case BootstrapProviderType :
132+ return 1
133+ case ControlPlaneProviderType :
134+ return 2
135+ case InfrastructureProviderType :
136+ return 3
81137 default :
82- return ProviderTypeUnknown
138+ return 4
83139 }
84140}
85141
86- // InstanceName return the instance name for the provider, that is composed by the provider name and the namespace
87- // where the provider is installed (nb. clusterctl does not support multiple instances of the same provider to be
88- // installed in the same namespace)
89- func (p * Provider ) InstanceName () string {
90- return types.NamespacedName {Namespace : p .Namespace , Name : p .Name }.String ()
91- }
92-
93- // HasWatchingOverlapWith returns true if the provider has an overlapping watching namespace with another provider.
94- func (p * Provider ) HasWatchingOverlapWith (other Provider ) bool {
95- return p .WatchedNamespace == "" || p .WatchedNamespace == other .WatchedNamespace || other .WatchedNamespace == ""
96- }
97-
98- // Equals returns true if two providers are exactly the same.
99- func (p * Provider ) Equals (other Provider ) bool {
100- return p .Name == other .Name &&
101- p .Namespace == other .Namespace &&
102- p .Type == other .Type &&
103- p .WatchedNamespace == other .WatchedNamespace &&
104- p .Version == other .Version
105- }
106-
107142// +kubebuilder:object:root=true
108143
109144// ProviderList contains a list of Provider
@@ -113,15 +148,15 @@ type ProviderList struct {
113148 Items []Provider `json:"items"`
114149}
115150
116- func (l * ProviderList ) FilterByName ( name string ) []Provider {
151+ func (l * ProviderList ) FilterByNamespace ( namespace string ) []Provider {
117152 return l .filterBy (func (p Provider ) bool {
118- return p .Name == name
153+ return p .Namespace == namespace
119154 })
120155}
121156
122- func (l * ProviderList ) FilterByNamespace ( namespace string ) []Provider {
157+ func (l * ProviderList ) FilterByProviderAndType ( provider string , providerType ProviderType ) []Provider {
123158 return l .filterBy (func (p Provider ) bool {
124- return p .Namespace == namespace
159+ return p .Provider == provider && p . Type == string ( providerType )
125160 })
126161}
127162
0 commit comments