Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit c9ee751

Browse files
committedFeb 16, 2022
feat: setup reference-addon api and controller
Signed-off-by: Yashvardhan Kukreja <[email protected]>
1 parent d34e1be commit c9ee751

File tree

6 files changed

+301
-9
lines changed

6 files changed

+301
-9
lines changed
 
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package v1alpha1
2+
3+
import (
4+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
5+
)
6+
7+
// ReferenceAddonSpec defines the desired state of ReferenceAddon.
8+
type ReferenceAddonSpec struct {
9+
}
10+
11+
// ReferenceAddonStatus defines the observed state of ReferenceAddon
12+
type ReferenceAddonStatus struct {
13+
ObservedGeneration int64 `json:"observedGeneration,omitempty"`
14+
Conditions []metav1.Condition `json:"conditions,omitempty"`
15+
}
16+
17+
// +kubebuilder:object:root=true
18+
// +kubebuilder:subresource:status
19+
// +kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp"
20+
type ReferenceAddon struct {
21+
metav1.TypeMeta `json:",inline"`
22+
metav1.ObjectMeta `json:"metadata,omitempty"`
23+
24+
Spec ReferenceAddonSpec `json:"spec,omitempty"`
25+
Status ReferenceAddonStatus `json:"status,omitempty"`
26+
}
27+
28+
// ReferenceAddonList contains a list of ReferenceAddons
29+
// +kubebuilder:object:root=true
30+
type ReferenceAddonList struct {
31+
metav1.TypeMeta `json:",inline"`
32+
metav1.ListMeta `json:"metadata,omitempty"`
33+
Items []ReferenceAddon `json:"items"`
34+
}
35+
36+
func init() {
37+
SchemeBuilder.Register(&ReferenceAddon{}, &ReferenceAddonList{})
38+
}

‎apis/reference/v1alpha1/zz_generated.deepcopy.go

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

‎cmd/reference-addon-manager/main.go

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414
"sigs.k8s.io/controller-runtime/pkg/manager"
1515

1616
refapis "github.com/openshift/reference-addon/apis"
17-
// "github.com/openshift/reference-addon/internal/controllers"
17+
"github.com/openshift/reference-addon/internal/controllers"
1818
)
1919

2020
var (
@@ -92,14 +92,17 @@ func main() {
9292
}
9393
}
9494

95-
// if err = (&controllers.AddonReconciler{
96-
// Client: mgr.GetClient(),
97-
// Log: ctrl.Log.WithName("controllers").WithName("Addon"),
98-
// Scheme: mgr.GetScheme(),
99-
// }).SetupWithManager(mgr); err != nil {
100-
// setupLog.Error(err, "unable to create controller", "controller", "Addon")
101-
// os.Exit(1)
102-
// }
95+
// the following section hooks up a heartbeat reporter with the current addon/operator
96+
r := controllers.ReferenceAddonReconciler{
97+
Client: mgr.GetClient(),
98+
Log: ctrl.Log.WithName("controllers").WithName("ReferenceAddon"),
99+
Scheme: mgr.GetScheme(),
100+
}
101+
102+
if err = r.SetupWithManager(mgr); err != nil {
103+
setupLog.Error(err, "unable to create controller", "controller", "ReferenceAddon")
104+
os.Exit(1)
105+
}
103106

104107
setupLog.Info("starting manager")
105108
if err := mgr.Start(ctrl.SetupSignalHandler()); err != nil {
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
2+
---
3+
apiVersion: apiextensions.k8s.io/v1
4+
kind: CustomResourceDefinition
5+
metadata:
6+
annotations:
7+
controller-gen.kubebuilder.io/version: v0.5.0
8+
creationTimestamp: null
9+
name: referenceaddons.reference.addons.managed.openshift.io
10+
spec:
11+
group: reference.addons.managed.openshift.io
12+
names:
13+
kind: ReferenceAddon
14+
listKind: ReferenceAddonList
15+
plural: referenceaddons
16+
singular: referenceaddon
17+
scope: Namespaced
18+
versions:
19+
- additionalPrinterColumns:
20+
- jsonPath: .metadata.creationTimestamp
21+
name: Age
22+
type: date
23+
name: v1alpha1
24+
schema:
25+
openAPIV3Schema:
26+
properties:
27+
apiVersion:
28+
description: 'APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
29+
type: string
30+
kind:
31+
description: 'Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
32+
type: string
33+
metadata:
34+
type: object
35+
spec:
36+
description: ReferenceAddonSpec defines the desired state of ReferenceAddon.
37+
type: object
38+
status:
39+
description: ReferenceAddonStatus defines the observed state of ReferenceAddon
40+
properties:
41+
conditions:
42+
items:
43+
description: "Condition contains details for one aspect of the current state of this API Resource. --- This struct is intended for direct use as an array at the field path .status.conditions. For example, type FooStatus struct{ // Represents the observations of a foo's current state. // Known .status.conditions.type are: \"Available\", \"Progressing\", and \"Degraded\" // +patchMergeKey=type // +patchStrategy=merge // +listType=map // +listMapKey=type Conditions []metav1.Condition `json:\"conditions,omitempty\" patchStrategy:\"merge\" patchMergeKey:\"type\" protobuf:\"bytes,1,rep,name=conditions\"` \n // other fields }"
44+
properties:
45+
lastTransitionTime:
46+
description: lastTransitionTime is the last time the condition transitioned from one status to another. This should be when the underlying condition changed. If that is not known, then using the time when the API field changed is acceptable.
47+
format: date-time
48+
type: string
49+
message:
50+
description: message is a human readable message indicating details about the transition. This may be an empty string.
51+
maxLength: 32768
52+
type: string
53+
observedGeneration:
54+
description: observedGeneration represents the .metadata.generation that the condition was set based upon. For instance, if .metadata.generation is currently 12, but the .status.conditions[x].observedGeneration is 9, the condition is out of date with respect to the current state of the instance.
55+
format: int64
56+
minimum: 0
57+
type: integer
58+
reason:
59+
description: reason contains a programmatic identifier indicating the reason for the condition's last transition. Producers of specific condition types may define expected values and meanings for this field, and whether the values are considered a guaranteed API. The value should be a CamelCase string. This field may not be empty.
60+
maxLength: 1024
61+
minLength: 1
62+
pattern: ^[A-Za-z]([A-Za-z0-9_,:]*[A-Za-z0-9_])?$
63+
type: string
64+
status:
65+
description: status of the condition, one of True, False, Unknown.
66+
enum:
67+
- "True"
68+
- "False"
69+
- Unknown
70+
type: string
71+
type:
72+
description: type of condition in CamelCase or in foo.example.com/CamelCase. --- Many .condition.type values are consistent across resources like Available, but because arbitrary conditions can be useful (see .node.status.conditions), the ability to deconflict is important. The regex it matches is (dns1123SubdomainFmt/)?(qualifiedNameFmt)
73+
maxLength: 316
74+
pattern: ^([a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*/)?(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])$
75+
type: string
76+
required:
77+
- lastTransitionTime
78+
- message
79+
- reason
80+
- status
81+
- type
82+
type: object
83+
type: array
84+
observedGeneration:
85+
format: int64
86+
type: integer
87+
type: object
88+
type: object
89+
served: true
90+
storage: true
91+
subresources:
92+
status: {}
93+
status:
94+
acceptedNames:
95+
kind: ""
96+
plural: ""
97+
conditions: []
98+
storedVersions: []

‎config/example/reference-addon.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
apiVersion: reference.addons.managed.openshift.io/v1alpha1
2+
kind: ReferenceAddon
3+
metadata:
4+
name: reference-addon
5+
namespace: reference-addon
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package controllers
2+
3+
import (
4+
"context"
5+
"strings"
6+
7+
"github.com/go-logr/logr"
8+
"k8s.io/apimachinery/pkg/runtime"
9+
ctrl "sigs.k8s.io/controller-runtime"
10+
"sigs.k8s.io/controller-runtime/pkg/client"
11+
12+
refapisv1alpha1 "github.com/openshift/reference-addon/apis/reference/v1alpha1"
13+
)
14+
15+
type ReferenceAddonReconciler struct {
16+
client.Client
17+
Log logr.Logger
18+
Scheme *runtime.Scheme
19+
}
20+
21+
func (r *ReferenceAddonReconciler) Reconcile(
22+
ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
23+
log := r.Log.WithValues("addon", req.NamespacedName.String())
24+
25+
// dummy code to indicate reconciliation of the reference-addon object
26+
if strings.HasPrefix(req.NamespacedName.Name, "redhat-") {
27+
log.Info("reconciling for a reference addon object prefixed by redhat- ")
28+
} else if strings.HasPrefix(req.NamespacedName.Name, "reference-addon") {
29+
log.Info("reconciling for a reference addon object named reference-addon")
30+
} else {
31+
log.Info("reconciling for a reference addon object not prefixed by redhat- or named reference-addon")
32+
}
33+
34+
return ctrl.Result{}, nil
35+
}
36+
37+
func (r *ReferenceAddonReconciler) SetupWithManager(mgr ctrl.Manager) error {
38+
return ctrl.NewControllerManagedBy(mgr).
39+
For(&refapisv1alpha1.ReferenceAddon{}).
40+
Complete(r)
41+
}

0 commit comments

Comments
 (0)