@@ -70,14 +70,42 @@ func (r *AnsibleOperatorReconciler) Reconcile(request reconcile.Request) (reconc
70
70
return reconcile.Result {}, nil
71
71
}
72
72
73
- s := u .Object ["spec" ]
74
- _ , ok := s .(map [string ]interface {})
73
+ spec := u .Object ["spec" ]
74
+ _ , ok := spec .(map [string ]interface {})
75
75
if ! ok {
76
- logrus .Warnf ("spec was not found" )
76
+ logrus .Debugf ("spec was not found" )
77
77
u .Object ["spec" ] = map [string ]interface {}{}
78
- r .Client .Update (context .TODO (), u )
78
+ err = r .Client .Update (context .TODO (), u )
79
+ if err != nil {
80
+ return reconcile.Result {}, err
81
+ }
82
+ return reconcile.Result {Requeue : true }, nil
83
+ }
84
+ status := u .Object ["status" ]
85
+ _ , ok = status .(map [string ]interface {})
86
+ if ! ok {
87
+ logrus .Debugf ("status was not found" )
88
+ u .Object ["status" ] = map [string ]interface {}{}
89
+ err = r .Client .Update (context .TODO (), u )
90
+ if err != nil {
91
+ return reconcile.Result {}, err
92
+ }
79
93
return reconcile.Result {Requeue : true }, nil
80
94
}
95
+
96
+ // If status is an empty map we can assume CR was just created
97
+ if len (u .Object ["status" ].(map [string ]interface {})) == 0 {
98
+ logrus .Debugf ("Setting phase status to %v" , StatusPhaseCreating )
99
+ u .Object ["status" ] = ResourceStatus {
100
+ Phase : StatusPhaseCreating ,
101
+ }
102
+ err = r .Client .Update (context .TODO (), u )
103
+ if err != nil {
104
+ return reconcile.Result {}, err
105
+ }
106
+ return reconcile.Result {Requeue : true }, nil
107
+ }
108
+
81
109
ownerRef := metav1.OwnerReference {
82
110
APIVersion : u .GetAPIVersion (),
83
111
Kind : u .GetKind (),
0 commit comments