Skip to content

Commit d8b5fbb

Browse files
authored
feat: Add ClusterAddonSet and ClusterAddon API types (#26)
As discussed, and influenced by CAPI resources such as `MachineSet`, this PR adds initial API kinds for `ClusterAddonSet` and `ClusterAddon`.
1 parent bbc6a01 commit d8b5fbb

File tree

8 files changed

+427
-24
lines changed

8 files changed

+427
-24
lines changed

api/v1alpha1/clusteraddon_types.go

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,24 @@
44
package v1alpha1
55

66
import (
7+
corev1 "k8s.io/api/core/v1"
78
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
89
)
910

10-
// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
11-
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.
12-
1311
// ClusterAddonSpec defines the desired state of ClusterAddon.
1412
type ClusterAddonSpec struct {
15-
// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
16-
// Important: Run "make" to regenerate code after modifying this file
17-
18-
// Foo is an example field of ClusterAddon. Edit clusteraddon_types.go to remove/update
19-
Foo string `json:"foo,omitempty"`
13+
// ImplementationRef is a required reference to a custom resource
14+
// offered by an cluster addon provider.
15+
ImplementationRef corev1.TypedLocalObjectReference `json:"implementationRef"`
16+
17+
// Version defines the desired addon version.
18+
// This field is meant to be optionally used by addon providers.
19+
// +optional
20+
Version *string `json:"version,omitempty"`
2021
}
2122

2223
// ClusterAddonStatus defines the observed state of ClusterAddon.
23-
type ClusterAddonStatus struct {
24-
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
25-
// Important: Run "make" to regenerate code after modifying this file
26-
}
24+
type ClusterAddonStatus struct{}
2725

2826
//+kubebuilder:object:root=true
2927
//+kubebuilder:subresource:status

api/v1alpha1/clusteraddonset_types.go

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// Copyright 2023 D2iQ, Inc. All rights reserved.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
package v1alpha1
5+
6+
import (
7+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
8+
)
9+
10+
// ClusterAddonSetSpec defines the desired state of ClusterAddonSet.
11+
type ClusterAddonSetSpec struct {
12+
// ClusterSelector selects Clusters in the same namespace with a label that matches the specified label selector.
13+
ClusterSelector metav1.LabelSelector `json:"clusterSelector"`
14+
15+
Template ClusterAddonSetTemplateSpec `json:"template,omitempty"`
16+
}
17+
18+
// ClusterAddonSetTemplateSpec describes the data needed to create a ClusterAddon from a template.
19+
type ClusterAddonSetTemplateSpec struct {
20+
// Standard object's metadata.
21+
// More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata
22+
// +optional
23+
ObjectMeta `json:"metadata,omitempty"`
24+
25+
// Specification of the desired state of the cluster addon.
26+
// More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#spec-and-status
27+
// +optional
28+
Spec ClusterAddonSpec `json:"spec,omitempty"`
29+
}
30+
31+
// ClusterAddonSetStatus defines the observed state of ClusterAddon.
32+
type ClusterAddonSetStatus struct{}
33+
34+
//+kubebuilder:object:root=true
35+
//+kubebuilder:subresource:status
36+
37+
// ClusterAddonSet is the Schema for the clusteraddons API.
38+
type ClusterAddonSet struct {
39+
metav1.TypeMeta `json:",inline"`
40+
metav1.ObjectMeta `json:"metadata,omitempty"`
41+
42+
Spec ClusterAddonSetSpec `json:"spec,omitempty"`
43+
Status ClusterAddonSetStatus `json:"status,omitempty"`
44+
}
45+
46+
//+kubebuilder:object:root=true
47+
48+
// ClusterAddonSetList contains a list of ClusterAddon.
49+
type ClusterAddonSetList struct {
50+
metav1.TypeMeta `json:",inline"`
51+
metav1.ListMeta `json:"metadata,omitempty"`
52+
Items []ClusterAddonSet `json:"items"`
53+
}
54+
55+
//nolint:gochecknoinits // Idiomatic way to register k8s API kinds.
56+
func init() {
57+
SchemeBuilder.Register(&ClusterAddonSet{}, &ClusterAddonSetList{})
58+
}

api/v1alpha1/common_types.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Copyright 2023 D2iQ, Inc. All rights reserved.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
package v1alpha1
5+
6+
// ObjectMeta is metadata that all persisted resources must have, which includes all objects
7+
// users must create. This is a copy of customizable fields from metav1.ObjectMeta.
8+
//
9+
// For more details on why this is included instead of using metav1.ObjectMeta directly, see
10+
// https://github.com/kubernetes-sigs/cluster-api/blob/v1.3.3/api/v1beta1/common_types.go#L175-L195.
11+
type ObjectMeta struct {
12+
// Map of string keys and values that can be used to organize and categorize
13+
// (scope and select) objects. May match selectors of replication controllers
14+
// and services.
15+
// More info: http://kubernetes.io/docs/user-guide/labels
16+
// +optional
17+
Labels map[string]string `json:"labels,omitempty"`
18+
19+
// Annotations is an unstructured key value map stored with a resource that may be
20+
// set by external tools to store and retrieve arbitrary metadata. They are not
21+
// queryable and should be preserved when modifying objects.
22+
// More info: http://kubernetes.io/docs/user-guide/annotations
23+
// +optional
24+
Annotations map[string]string `json:"annotations,omitempty"`
25+
}

api/v1alpha1/zz_generated.deepcopy.go

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

charts/capi-runtime-extensions/crds/clusteraddons.labs.d2iq.io_clusteraddons.yaml

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,33 @@ spec:
3535
spec:
3636
description: ClusterAddonSpec defines the desired state of ClusterAddon.
3737
properties:
38-
foo:
39-
description: Foo is an example field of ClusterAddon. Edit clusteraddon_types.go
40-
to remove/update
38+
implementationRef:
39+
description: ImplementationRef is a required reference to a custom
40+
resource offered by an cluster addon provider.
41+
properties:
42+
apiGroup:
43+
description: APIGroup is the group for the resource being referenced.
44+
If APIGroup is not specified, the specified Kind must be in
45+
the core API group. For any other third-party types, APIGroup
46+
is required.
47+
type: string
48+
kind:
49+
description: Kind is the type of resource being referenced
50+
type: string
51+
name:
52+
description: Name is the name of resource being referenced
53+
type: string
54+
required:
55+
- kind
56+
- name
57+
type: object
58+
x-kubernetes-map-type: atomic
59+
version:
60+
description: Version defines the desired addon version. This field
61+
is meant to be optionally used by addon providers.
4162
type: string
63+
required:
64+
- implementationRef
4265
type: object
4366
status:
4467
description: ClusterAddonStatus defines the observed state of ClusterAddon.

0 commit comments

Comments
 (0)