@@ -15,42 +15,51 @@ import (
15
15
)
16
16
17
17
type ProviderReconciler struct {
18
- Name string
19
18
schema.GroupVersionKind
20
- client.Client
19
+ PlatformClient client.Client
20
+ }
21
+
22
+ func (r * ProviderReconciler ) ControllerName () string {
23
+ return r .GroupVersionKind .String ()
21
24
}
22
25
23
26
func (r * ProviderReconciler ) Reconcile (ctx context.Context , req ctrl.Request ) (ctrl.Result , error ) {
24
- log := logging .FromContextOrPanic (ctx ).WithName (r .Name )
27
+ log := logging .FromContextOrPanic (ctx ).WithName (r .ControllerName ())
28
+ ctx = logging .NewContext (ctx , log )
29
+ log .Debug ("Starting reconcile" )
25
30
26
- deployable := & unstructured.Unstructured {}
27
- deployable .SetGroupVersionKind (r .GroupVersionKind )
31
+ provider := & unstructured.Unstructured {}
32
+ provider .SetGroupVersionKind (r .GroupVersionKind )
28
33
29
- if err := r .Get (ctx , req .NamespacedName , deployable ); err != nil {
30
- return ctrl.Result {}, err
34
+ if err := r .PlatformClient . Get (ctx , req .NamespacedName , provider ); err != nil {
35
+ return ctrl.Result {}, fmt . Errorf ( "failed to get provider resource: %w" , err )
31
36
}
32
37
33
- deployableOrig := deployable .DeepCopy ()
34
-
35
- log .Info ("Reconciling deployable" )
38
+ providerOrig := provider .DeepCopy ()
36
39
37
- deployableSpec := v1alpha1.DeploymentSpec {}
38
- deploymentSpecRaw , found , err := unstructured .NestedFieldNoCopy (deployable .Object , "spec" , "deploymentSpec " )
40
+ deploymentSpec := v1alpha1.DeploymentSpec {}
41
+ deploymentSpecRaw , found , err := unstructured .NestedFieldNoCopy (provider .Object , "spec" )
39
42
if ! found {
40
- return ctrl.Result {}, fmt .Errorf ("deploymentSpec not found" )
43
+ return ctrl.Result {}, fmt .Errorf ("provider spec not found" )
41
44
}
42
45
if err != nil {
43
- return ctrl.Result {}, err
46
+ return ctrl.Result {}, fmt . Errorf ( "failed to get provider spec: %w" , err )
44
47
}
45
48
46
- if err = runtime .DefaultUnstructuredConverter .FromUnstructured (deploymentSpecRaw .(map [string ]interface {}), & deployableSpec ); err != nil {
47
- return ctrl.Result {}, err
49
+ if err = runtime .DefaultUnstructuredConverter .FromUnstructured (deploymentSpecRaw .(map [string ]interface {}), & deploymentSpec ); err != nil {
50
+ return ctrl.Result {}, fmt . Errorf ( "failed to convert provider spec: %w" , err )
48
51
}
49
52
50
- log .Info ("DeployableSpec" , "deployableSpec" , deployableSpec )
53
+ log .Info ("DeployableSpec" , "deploymentSpec" , deploymentSpec )
54
+
55
+ //if provider.GetDeletionTimestamp().IsZero() {
56
+ // res, err = r.handleCreateUpdateOperation(ctx, provider)
57
+ //} else {
58
+ // res, err = r.handleDeleteOperation(ctx, provider)
59
+ //}
51
60
52
61
deployableStatus := v1alpha1.DeploymentStatus {}
53
- deploymentStatusRaw , found , _ := unstructured .NestedFieldNoCopy (deployable .Object , "status" , "deploymentStatus" )
62
+ deploymentStatusRaw , found , _ := unstructured .NestedFieldNoCopy (provider .Object , "status" , "deploymentStatus" )
54
63
if found {
55
64
if err = runtime .DefaultUnstructuredConverter .FromUnstructured (deploymentStatusRaw .(map [string ]interface {}), & deployableStatus ); err != nil {
56
65
return ctrl.Result {}, err
@@ -65,22 +74,30 @@ func (r *ProviderReconciler) Reconcile(ctx context.Context, req ctrl.Request) (c
65
74
return ctrl.Result {}, err
66
75
}
67
76
68
- statusRaw , found , _ := unstructured .NestedFieldNoCopy (deployable .Object , "status" )
77
+ statusRaw , found , _ := unstructured .NestedFieldNoCopy (provider .Object , "status" )
69
78
if ! found {
70
79
statusRaw = map [string ]interface {}{}
71
- if err = unstructured .SetNestedField (deployable .Object , statusRaw .(map [string ]interface {}), "status" ); err != nil {
80
+ if err = unstructured .SetNestedField (provider .Object , statusRaw .(map [string ]interface {}), "status" ); err != nil {
72
81
return ctrl.Result {}, err
73
82
}
74
83
}
75
84
76
- if err = unstructured .SetNestedField (deployable .Object , deploymentSpecRaw , "status" , "deploymentStatus" ); err != nil {
85
+ if err = unstructured .SetNestedField (provider .Object , deploymentSpecRaw , "status" , "deploymentStatus" ); err != nil {
77
86
return ctrl.Result {}, err
78
87
}
79
88
80
89
// patch the status
81
- if err = r .Status ().Patch (ctx , deployable , client .MergeFrom (deployableOrig )); err != nil {
90
+ if err = r .PlatformClient . Status ().Patch (ctx , provider , client .MergeFrom (providerOrig )); err != nil {
82
91
return ctrl.Result {}, err
83
92
}
84
93
85
94
return ctrl.Result {}, nil
86
95
}
96
+
97
+ func (r * ProviderReconciler ) handleCreateUpdateOperation (ctx context.Context , provider * unstructured.Unstructured ) (ctrl.Result , error ) {
98
+ return ctrl.Result {}, nil
99
+ }
100
+
101
+ func (r * ProviderReconciler ) handleDeleteOperation (ctx context.Context , provider * unstructured.Unstructured ) (ctrl.Result , error ) {
102
+ return ctrl.Result {}, nil
103
+ }
0 commit comments