|
5 | 5 | "fmt"
|
6 | 6 | "time"
|
7 | 7 |
|
8 |
| - appsv1 "k8s.io/api/apps/v1" |
9 | 8 | "k8s.io/apimachinery/pkg/api/errors"
|
10 |
| - utilerrors "k8s.io/apimachinery/pkg/util/errors" |
| 9 | + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" |
11 | 10 | utilruntime "k8s.io/apimachinery/pkg/util/runtime"
|
12 | 11 | "k8s.io/apimachinery/pkg/util/wait"
|
13 | 12 | appsv1informers "k8s.io/client-go/informers/apps/v1"
|
@@ -122,65 +121,38 @@ func (c *NodeCADaemonController) sync() error {
|
122 | 121 | Status: operatorv1.ConditionUnknown,
|
123 | 122 | }
|
124 | 123 |
|
125 |
| - dsObj, err := gen.Get() |
| 124 | + _, err := gen.Get() |
126 | 125 | if errors.IsNotFound(err) {
|
127 |
| - availableCondition.Status = operatorv1.ConditionFalse |
128 |
| - availableCondition.Reason = "NotFound" |
129 |
| - availableCondition.Message = "The daemon set node-ca does not exist" |
| 126 | + availableCondition.Status = operatorv1.ConditionTrue |
| 127 | + availableCondition.Reason = "AsExpected" |
| 128 | + availableCondition.Message = "The daemon set node-ca is removed" |
130 | 129 |
|
131 |
| - progressingCondition.Status = operatorv1.ConditionTrue |
132 |
| - progressingCondition.Reason = "NotFound" |
133 |
| - progressingCondition.Message = "The daemon set node-ca does not exist" |
| 130 | + progressingCondition.Status = operatorv1.ConditionFalse |
| 131 | + progressingCondition.Reason = "AsExpected" |
| 132 | + progressingCondition.Message = "The daemon set node-ca is removed" |
134 | 133 | } else if err != nil {
|
135 | 134 | availableCondition.Reason = "Unknown"
|
136 |
| - availableCondition.Message = fmt.Sprintf("Unable to check daemon set availability: %s", err) |
| 135 | + availableCondition.Message = fmt.Sprintf("Unable to check daemon set existence: %s", err) |
137 | 136 |
|
138 | 137 | progressingCondition.Reason = "Unknown"
|
139 |
| - progressingCondition.Message = fmt.Sprintf("Unable to check daemon set progress: %s", err) |
| 138 | + progressingCondition.Message = fmt.Sprintf("Unable to check daemon set existence: %s", err) |
140 | 139 | } else {
|
141 |
| - ds := dsObj.(*appsv1.DaemonSet) |
142 |
| - if ds.Status.NumberAvailable > 0 { |
143 |
| - availableCondition.Status = operatorv1.ConditionTrue |
144 |
| - availableCondition.Reason = "AsExpected" |
145 |
| - availableCondition.Message = "The daemon set node-ca has available replicas" |
146 |
| - } else { |
147 |
| - availableCondition.Status = operatorv1.ConditionFalse |
148 |
| - availableCondition.Reason = "NoAvailableReplicas" |
149 |
| - availableCondition.Message = "The daemon set node-ca does not have available replicas" |
| 140 | + gracePeriod := int64(0) |
| 141 | + propagationPolicy := metav1.DeletePropagationForeground |
| 142 | + opts := metav1.DeleteOptions{ |
| 143 | + GracePeriodSeconds: &gracePeriod, |
| 144 | + PropagationPolicy: &propagationPolicy, |
150 | 145 | }
|
| 146 | + err := gen.Delete(opts) |
| 147 | + if err != nil && !errors.IsNotFound(err) { |
| 148 | + availableCondition.Reason = "Unknown" |
| 149 | + availableCondition.Message = fmt.Sprintf("Unable to delete daemon set: %s", err) |
151 | 150 |
|
152 |
| - if ds.Generation != ds.Status.ObservedGeneration { |
153 |
| - progressingCondition.Status = operatorv1.ConditionTrue |
154 |
| - progressingCondition.Reason = "Progressing" |
155 |
| - progressingCondition.Message = "The daemon set node-ca is updating node pods" |
156 |
| - } else if ds.Status.NumberUnavailable > 0 { |
157 |
| - progressingCondition.Status = operatorv1.ConditionTrue |
158 |
| - progressingCondition.Reason = "Unavailable" |
159 |
| - progressingCondition.Message = "The daemon set node-ca is deploying node pods" |
160 |
| - } else { |
161 |
| - progressingCondition.Status = operatorv1.ConditionFalse |
162 |
| - progressingCondition.Reason = "AsExpected" |
163 |
| - progressingCondition.Message = "The daemon set node-ca is deployed" |
| 151 | + progressingCondition.Reason = "Unknown" |
| 152 | + progressingCondition.Message = fmt.Sprintf("Unable to delete daemon set: %s", err) |
164 | 153 | }
|
165 | 154 | }
|
166 | 155 |
|
167 |
| - err = resource.ApplyMutator(gen) |
168 |
| - if err != nil { |
169 |
| - _, _, updateError := v1helpers.UpdateStatus( |
170 |
| - ctx, |
171 |
| - c.operatorClient, |
172 |
| - v1helpers.UpdateConditionFn(availableCondition), |
173 |
| - v1helpers.UpdateConditionFn(progressingCondition), |
174 |
| - v1helpers.UpdateConditionFn(operatorv1.OperatorCondition{ |
175 |
| - Type: "NodeCADaemonControllerDegraded", |
176 |
| - Status: operatorv1.ConditionTrue, |
177 |
| - Reason: "Error", |
178 |
| - Message: err.Error(), |
179 |
| - }), |
180 |
| - ) |
181 |
| - return utilerrors.NewAggregate([]error{err, updateError}) |
182 |
| - } |
183 |
| - |
184 | 156 | _, _, err = v1helpers.UpdateStatus(
|
185 | 157 | ctx,
|
186 | 158 | c.operatorClient,
|
|
0 commit comments