Jian Li | ac31f65 | 2021-01-17 02:18:30 +0900 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2021-present Open Networking Foundation |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | package org.onosproject.kubevirtnetworking.impl; |
| 17 | |
| 18 | import com.google.common.collect.ImmutableSet; |
| 19 | import io.fabric8.kubernetes.api.model.Affinity; |
| 20 | import io.fabric8.kubernetes.api.model.Capabilities; |
| 21 | import io.fabric8.kubernetes.api.model.ConfigMapEnvSource; |
| 22 | import io.fabric8.kubernetes.api.model.ConfigMapKeySelector; |
Jian Li | c42f3cb | 2021-07-21 18:32:31 +0900 | [diff] [blame] | 23 | import io.fabric8.kubernetes.api.model.ConfigMapProjection; |
Jian Li | ac31f65 | 2021-01-17 02:18:30 +0900 | [diff] [blame] | 24 | import io.fabric8.kubernetes.api.model.ConfigMapVolumeSource; |
| 25 | import io.fabric8.kubernetes.api.model.Container; |
| 26 | import io.fabric8.kubernetes.api.model.ContainerPort; |
| 27 | import io.fabric8.kubernetes.api.model.ContainerState; |
| 28 | import io.fabric8.kubernetes.api.model.ContainerStateRunning; |
| 29 | import io.fabric8.kubernetes.api.model.ContainerStateTerminated; |
| 30 | import io.fabric8.kubernetes.api.model.ContainerStateWaiting; |
| 31 | import io.fabric8.kubernetes.api.model.ContainerStatus; |
Jian Li | c42f3cb | 2021-07-21 18:32:31 +0900 | [diff] [blame] | 32 | import io.fabric8.kubernetes.api.model.DownwardAPIProjection; |
Jian Li | b6dc08f | 2021-03-24 15:24:18 +0900 | [diff] [blame] | 33 | import io.fabric8.kubernetes.api.model.DownwardAPIVolumeFile; |
| 34 | import io.fabric8.kubernetes.api.model.DownwardAPIVolumeSource; |
Jian Li | ac31f65 | 2021-01-17 02:18:30 +0900 | [diff] [blame] | 35 | import io.fabric8.kubernetes.api.model.EmptyDirVolumeSource; |
| 36 | import io.fabric8.kubernetes.api.model.EnvFromSource; |
| 37 | import io.fabric8.kubernetes.api.model.EnvVar; |
| 38 | import io.fabric8.kubernetes.api.model.EnvVarSource; |
| 39 | import io.fabric8.kubernetes.api.model.ExecAction; |
| 40 | import io.fabric8.kubernetes.api.model.FieldsV1; |
| 41 | import io.fabric8.kubernetes.api.model.HTTPGetAction; |
| 42 | import io.fabric8.kubernetes.api.model.HTTPHeader; |
Jian Li | fc72425 | 2021-01-29 00:01:51 +0900 | [diff] [blame] | 43 | import io.fabric8.kubernetes.api.model.Handler; |
Jian Li | ac31f65 | 2021-01-17 02:18:30 +0900 | [diff] [blame] | 44 | import io.fabric8.kubernetes.api.model.HostPathVolumeSource; |
| 45 | import io.fabric8.kubernetes.api.model.IntOrString; |
| 46 | import io.fabric8.kubernetes.api.model.KeyToPath; |
| 47 | import io.fabric8.kubernetes.api.model.LabelSelector; |
| 48 | import io.fabric8.kubernetes.api.model.LabelSelectorRequirement; |
| 49 | import io.fabric8.kubernetes.api.model.Lifecycle; |
Jian Li | fc72425 | 2021-01-29 00:01:51 +0900 | [diff] [blame] | 50 | import io.fabric8.kubernetes.api.model.LocalObjectReference; |
Jian Li | ac31f65 | 2021-01-17 02:18:30 +0900 | [diff] [blame] | 51 | import io.fabric8.kubernetes.api.model.ManagedFieldsEntry; |
| 52 | import io.fabric8.kubernetes.api.model.NodeAffinity; |
| 53 | import io.fabric8.kubernetes.api.model.NodeSelector; |
| 54 | import io.fabric8.kubernetes.api.model.NodeSelectorRequirement; |
| 55 | import io.fabric8.kubernetes.api.model.NodeSelectorTerm; |
| 56 | import io.fabric8.kubernetes.api.model.ObjectFieldSelector; |
| 57 | import io.fabric8.kubernetes.api.model.ObjectMeta; |
| 58 | import io.fabric8.kubernetes.api.model.OwnerReference; |
| 59 | import io.fabric8.kubernetes.api.model.PersistentVolumeClaimVolumeSource; |
| 60 | import io.fabric8.kubernetes.api.model.Pod; |
| 61 | import io.fabric8.kubernetes.api.model.PodAffinity; |
| 62 | import io.fabric8.kubernetes.api.model.PodAffinityTerm; |
| 63 | import io.fabric8.kubernetes.api.model.PodAntiAffinity; |
| 64 | import io.fabric8.kubernetes.api.model.PodCondition; |
| 65 | import io.fabric8.kubernetes.api.model.PodIP; |
Jian Li | 106b382 | 2021-12-14 15:54:58 +0900 | [diff] [blame] | 66 | import io.fabric8.kubernetes.api.model.PodReadinessGate; |
Jian Li | ac31f65 | 2021-01-17 02:18:30 +0900 | [diff] [blame] | 67 | import io.fabric8.kubernetes.api.model.PodSecurityContext; |
| 68 | import io.fabric8.kubernetes.api.model.PodSpec; |
| 69 | import io.fabric8.kubernetes.api.model.PodStatus; |
| 70 | import io.fabric8.kubernetes.api.model.PreferredSchedulingTerm; |
| 71 | import io.fabric8.kubernetes.api.model.Probe; |
Jian Li | c42f3cb | 2021-07-21 18:32:31 +0900 | [diff] [blame] | 72 | import io.fabric8.kubernetes.api.model.ProjectedVolumeSource; |
Jian Li | ac31f65 | 2021-01-17 02:18:30 +0900 | [diff] [blame] | 73 | import io.fabric8.kubernetes.api.model.Quantity; |
| 74 | import io.fabric8.kubernetes.api.model.ResourceFieldSelector; |
| 75 | import io.fabric8.kubernetes.api.model.ResourceRequirements; |
| 76 | import io.fabric8.kubernetes.api.model.SELinuxOptions; |
Jian Li | 72f3dac | 2021-01-28 16:14:54 +0900 | [diff] [blame] | 77 | import io.fabric8.kubernetes.api.model.SeccompProfile; |
Jian Li | ac31f65 | 2021-01-17 02:18:30 +0900 | [diff] [blame] | 78 | import io.fabric8.kubernetes.api.model.SecretEnvSource; |
| 79 | import io.fabric8.kubernetes.api.model.SecretKeySelector; |
Jian Li | c42f3cb | 2021-07-21 18:32:31 +0900 | [diff] [blame] | 80 | import io.fabric8.kubernetes.api.model.SecretProjection; |
Jian Li | ac31f65 | 2021-01-17 02:18:30 +0900 | [diff] [blame] | 81 | import io.fabric8.kubernetes.api.model.SecretVolumeSource; |
| 82 | import io.fabric8.kubernetes.api.model.SecurityContext; |
Jian Li | c42f3cb | 2021-07-21 18:32:31 +0900 | [diff] [blame] | 83 | import io.fabric8.kubernetes.api.model.ServiceAccountTokenProjection; |
Jian Li | ac31f65 | 2021-01-17 02:18:30 +0900 | [diff] [blame] | 84 | import io.fabric8.kubernetes.api.model.TCPSocketAction; |
| 85 | import io.fabric8.kubernetes.api.model.Toleration; |
| 86 | import io.fabric8.kubernetes.api.model.Volume; |
| 87 | import io.fabric8.kubernetes.api.model.VolumeDevice; |
| 88 | import io.fabric8.kubernetes.api.model.VolumeMount; |
Jian Li | c42f3cb | 2021-07-21 18:32:31 +0900 | [diff] [blame] | 89 | import io.fabric8.kubernetes.api.model.VolumeProjection; |
Jian Li | ac31f65 | 2021-01-17 02:18:30 +0900 | [diff] [blame] | 90 | import io.fabric8.kubernetes.api.model.WeightedPodAffinityTerm; |
| 91 | import org.onlab.util.KryoNamespace; |
| 92 | import org.onosproject.core.ApplicationId; |
| 93 | import org.onosproject.core.CoreService; |
| 94 | import org.onosproject.kubevirtnetworking.api.KubevirtPodEvent; |
| 95 | import org.onosproject.kubevirtnetworking.api.KubevirtPodStore; |
| 96 | import org.onosproject.kubevirtnetworking.api.KubevirtPodStoreDelegate; |
| 97 | import org.onosproject.store.AbstractStore; |
| 98 | import org.onosproject.store.serializers.KryoNamespaces; |
| 99 | import org.onosproject.store.service.ConsistentMap; |
| 100 | import org.onosproject.store.service.MapEvent; |
| 101 | import org.onosproject.store.service.MapEventListener; |
| 102 | import org.onosproject.store.service.Serializer; |
| 103 | import org.onosproject.store.service.StorageService; |
| 104 | import org.onosproject.store.service.Versioned; |
| 105 | import org.osgi.service.component.annotations.Activate; |
| 106 | import org.osgi.service.component.annotations.Component; |
| 107 | import org.osgi.service.component.annotations.Deactivate; |
| 108 | import org.osgi.service.component.annotations.Reference; |
| 109 | import org.osgi.service.component.annotations.ReferenceCardinality; |
| 110 | import org.slf4j.Logger; |
| 111 | |
| 112 | import java.util.Collection; |
| 113 | import java.util.LinkedHashMap; |
| 114 | import java.util.Map; |
| 115 | import java.util.Set; |
| 116 | import java.util.concurrent.ExecutorService; |
| 117 | |
| 118 | import static com.google.common.base.Preconditions.checkArgument; |
| 119 | import static java.util.concurrent.Executors.newSingleThreadExecutor; |
| 120 | import static org.onlab.util.Tools.groupedThreads; |
| 121 | import static org.onosproject.kubevirtnetworking.api.KubevirtPodEvent.Type.KUBEVIRT_POD_ANNOTATION_ADDED; |
| 122 | import static org.onosproject.kubevirtnetworking.api.KubevirtPodEvent.Type.KUBEVIRT_POD_COMPLETED; |
| 123 | import static org.onosproject.kubevirtnetworking.api.KubevirtPodEvent.Type.KUBEVIRT_POD_CRASH_LOOP_BACK_OFF; |
| 124 | import static org.onosproject.kubevirtnetworking.api.KubevirtPodEvent.Type.KUBEVIRT_POD_CREATED; |
| 125 | import static org.onosproject.kubevirtnetworking.api.KubevirtPodEvent.Type.KUBEVIRT_POD_FAILED; |
| 126 | import static org.onosproject.kubevirtnetworking.api.KubevirtPodEvent.Type.KUBEVIRT_POD_PENDING; |
| 127 | import static org.onosproject.kubevirtnetworking.api.KubevirtPodEvent.Type.KUBEVIRT_POD_REMOVED; |
| 128 | import static org.onosproject.kubevirtnetworking.api.KubevirtPodEvent.Type.KUBEVIRT_POD_RUNNING; |
| 129 | import static org.onosproject.kubevirtnetworking.api.KubevirtPodEvent.Type.KUBEVIRT_POD_SUCCEEDED; |
| 130 | import static org.onosproject.kubevirtnetworking.api.KubevirtPodEvent.Type.KUBEVIRT_POD_UNKNOWN; |
| 131 | import static org.onosproject.kubevirtnetworking.api.KubevirtPodEvent.Type.KUBEVIRT_POD_UPDATED; |
| 132 | import static org.slf4j.LoggerFactory.getLogger; |
| 133 | |
| 134 | /** |
| 135 | * Implementation of kubevirt pod store using consistent map. |
| 136 | */ |
| 137 | @Component(immediate = true, service = KubevirtPodStore.class) |
| 138 | public class DistributedKubevirtPodStore |
| 139 | extends AbstractStore<KubevirtPodEvent, KubevirtPodStoreDelegate> |
| 140 | implements KubevirtPodStore { |
| 141 | private final Logger log = getLogger(getClass()); |
| 142 | |
| 143 | private static final String ERR_NOT_FOUND = " does not exist"; |
| 144 | private static final String ERR_DUPLICATE = " already exists"; |
| 145 | private static final String APP_ID = "org.onosproject.k8snetwork"; |
| 146 | |
| 147 | private static final String PENDING = "Pending"; |
| 148 | private static final String RUNNING = "Running"; |
| 149 | private static final String SUCCEEDED = "Succeeded"; |
| 150 | private static final String FAILED = "Failed"; |
| 151 | private static final String UNKNOWN = "Unknown"; |
| 152 | private static final String COMPLETED = "Completed"; |
| 153 | private static final String CRASH_LOOP_BACK_OFF = "CrashLoopBackOff"; |
| 154 | |
| 155 | private static final KryoNamespace |
| 156 | SERIALIZER_K8S_POD = KryoNamespace.newBuilder() |
| 157 | .register(KryoNamespaces.API) |
| 158 | .register(Pod.class) |
| 159 | .register(ObjectMeta.class) |
| 160 | .register(PodSpec.class) |
| 161 | .register(PodStatus.class) |
| 162 | .register(PodCondition.class) |
| 163 | .register(PodIP.class) |
| 164 | .register(Container.class) |
| 165 | .register(EnvVar.class) |
| 166 | .register(EnvVarSource.class) |
| 167 | .register(EnvFromSource.class) |
| 168 | .register(ConfigMapEnvSource.class) |
| 169 | .register(ConfigMapKeySelector.class) |
| 170 | .register(ObjectFieldSelector.class) |
| 171 | .register(ResourceFieldSelector.class) |
| 172 | .register(SecretKeySelector.class) |
| 173 | .register(Lifecycle.class) |
| 174 | .register(SecretEnvSource.class) |
| 175 | .register(ContainerStatus.class) |
| 176 | .register(ContainerState.class) |
| 177 | .register(ContainerStateRunning.class) |
| 178 | .register(ContainerStateTerminated.class) |
| 179 | .register(ContainerStateWaiting.class) |
| 180 | .register(OwnerReference.class) |
| 181 | .register(Probe.class) |
| 182 | .register(ExecAction.class) |
| 183 | .register(HTTPGetAction.class) |
| 184 | .register(HTTPHeader.class) |
| 185 | .register(TCPSocketAction.class) |
| 186 | .register(ContainerPort.class) |
| 187 | .register(ResourceRequirements.class) |
| 188 | .register(SecurityContext.class) |
| 189 | .register(PodSecurityContext.class) |
| 190 | .register(SELinuxOptions.class) |
Jian Li | 72f3dac | 2021-01-28 16:14:54 +0900 | [diff] [blame] | 191 | .register(SeccompProfile.class) |
Jian Li | fc72425 | 2021-01-29 00:01:51 +0900 | [diff] [blame] | 192 | .register(Handler.class) |
| 193 | .register(ExecAction.class) |
| 194 | .register(HTTPGetAction.class) |
| 195 | .register(TCPSocketAction.class) |
| 196 | .register(HTTPHeader.class) |
Jian Li | ac31f65 | 2021-01-17 02:18:30 +0900 | [diff] [blame] | 197 | .register(Volume.class) |
| 198 | .register(VolumeDevice.class) |
| 199 | .register(VolumeMount.class) |
| 200 | .register(IntOrString.class) |
| 201 | .register(Toleration.class) |
| 202 | .register(PersistentVolumeClaimVolumeSource.class) |
Jian Li | c42f3cb | 2021-07-21 18:32:31 +0900 | [diff] [blame] | 203 | .register(ProjectedVolumeSource.class) |
| 204 | .register(VolumeProjection.class) |
| 205 | .register(ConfigMapProjection.class) |
| 206 | .register(KeyToPath.class) |
| 207 | .register(DownwardAPIProjection.class) |
| 208 | .register(DownwardAPIVolumeFile.class) |
| 209 | .register(ObjectFieldSelector.class) |
| 210 | .register(ResourceFieldSelector.class) |
| 211 | .register(SecretProjection.class) |
| 212 | .register(Quantity.class) |
| 213 | .register(ServiceAccountTokenProjection.class) |
Jian Li | ac31f65 | 2021-01-17 02:18:30 +0900 | [diff] [blame] | 214 | .register(SecretVolumeSource.class) |
| 215 | .register(EmptyDirVolumeSource.class) |
| 216 | .register(Quantity.class) |
| 217 | .register(Capabilities.class) |
| 218 | .register(ConfigMapVolumeSource.class) |
| 219 | .register(KeyToPath.class) |
| 220 | .register(HostPathVolumeSource.class) |
| 221 | .register(Affinity.class) |
| 222 | .register(NodeAffinity.class) |
| 223 | .register(NodeSelector.class) |
| 224 | .register(NodeSelectorTerm.class) |
| 225 | .register(NodeSelectorRequirement.class) |
| 226 | .register(PreferredSchedulingTerm.class) |
| 227 | .register(PodAffinity.class) |
| 228 | .register(WeightedPodAffinityTerm.class) |
| 229 | .register(PodAffinityTerm.class) |
| 230 | .register(LabelSelector.class) |
| 231 | .register(LabelSelectorRequirement.class) |
Jian Li | fc72425 | 2021-01-29 00:01:51 +0900 | [diff] [blame] | 232 | .register(LocalObjectReference.class) |
Jian Li | ac31f65 | 2021-01-17 02:18:30 +0900 | [diff] [blame] | 233 | .register(PodAntiAffinity.class) |
| 234 | .register(ManagedFieldsEntry.class) |
Jian Li | b6dc08f | 2021-03-24 15:24:18 +0900 | [diff] [blame] | 235 | .register(DownwardAPIVolumeSource.class) |
| 236 | .register(DownwardAPIVolumeFile.class) |
| 237 | .register(ObjectFieldSelector.class) |
Jian Li | ac31f65 | 2021-01-17 02:18:30 +0900 | [diff] [blame] | 238 | .register(FieldsV1.class) |
Jian Li | 106b382 | 2021-12-14 15:54:58 +0900 | [diff] [blame] | 239 | .register(PodReadinessGate.class) |
Jian Li | ac31f65 | 2021-01-17 02:18:30 +0900 | [diff] [blame] | 240 | .register(LinkedHashMap.class) |
| 241 | .register(Collection.class) |
| 242 | .build(); |
| 243 | |
| 244 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
| 245 | protected CoreService coreService; |
| 246 | |
| 247 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
| 248 | protected StorageService storageService; |
| 249 | |
| 250 | private final ExecutorService eventExecutor = newSingleThreadExecutor( |
| 251 | groupedThreads(this.getClass().getSimpleName(), "event-handler", log)); |
| 252 | |
| 253 | private final MapEventListener<String, Pod> podMapListener = new KubevirtPodMapListener(); |
| 254 | |
| 255 | private ConsistentMap<String, Pod> podStore; |
| 256 | |
| 257 | @Activate |
| 258 | protected void activate() { |
| 259 | ApplicationId appId = coreService.registerApplication(APP_ID); |
| 260 | podStore = storageService.<String, Pod>consistentMapBuilder() |
| 261 | .withSerializer(Serializer.using(SERIALIZER_K8S_POD)) |
| 262 | .withName("kubevirt-pod-store") |
| 263 | .withApplicationId(appId) |
| 264 | .build(); |
| 265 | |
| 266 | podStore.addListener(podMapListener); |
| 267 | log.info("Started"); |
| 268 | } |
| 269 | |
| 270 | @Deactivate |
| 271 | protected void deactivate() { |
| 272 | podStore.removeListener(podMapListener); |
| 273 | eventExecutor.shutdown(); |
| 274 | log.info("Stopped"); |
| 275 | } |
| 276 | |
| 277 | @Override |
| 278 | public void createPod(Pod pod) { |
| 279 | podStore.compute(pod.getMetadata().getUid(), (uid, existing) -> { |
| 280 | final String error = pod.getMetadata().getUid() + ERR_DUPLICATE; |
| 281 | checkArgument(existing == null, error); |
| 282 | return pod; |
| 283 | }); |
| 284 | } |
| 285 | |
| 286 | @Override |
| 287 | public void updatePod(Pod pod) { |
| 288 | podStore.compute(pod.getMetadata().getUid(), (uid, existing) -> { |
| 289 | final String error = pod.getMetadata().getUid() + ERR_NOT_FOUND; |
| 290 | checkArgument(existing != null, error); |
| 291 | return pod; |
| 292 | }); |
| 293 | } |
| 294 | |
| 295 | @Override |
| 296 | public Pod removePod(String uid) { |
| 297 | Versioned<Pod> pod = podStore.remove(uid); |
| 298 | if (pod == null) { |
| 299 | final String error = uid + ERR_NOT_FOUND; |
| 300 | throw new IllegalArgumentException(error); |
| 301 | } |
| 302 | return pod.value(); |
| 303 | } |
| 304 | |
| 305 | @Override |
| 306 | public Pod pod(String uid) { |
| 307 | return podStore.asJavaMap().get(uid); |
| 308 | } |
| 309 | |
| 310 | @Override |
| 311 | public Set<Pod> pods() { |
| 312 | return ImmutableSet.copyOf(podStore.asJavaMap().values()); |
| 313 | } |
| 314 | |
| 315 | @Override |
| 316 | public void clear() { |
| 317 | podStore.clear(); |
| 318 | } |
| 319 | |
| 320 | private class KubevirtPodMapListener implements MapEventListener<String, Pod> { |
| 321 | |
| 322 | @Override |
| 323 | public void event(MapEvent<String, Pod> event) { |
| 324 | |
| 325 | switch (event.type()) { |
| 326 | case INSERT: |
| 327 | log.debug("Kubernetes pod created {}", event.newValue()); |
| 328 | eventExecutor.execute(() -> |
| 329 | notifyDelegate(new KubevirtPodEvent( |
| 330 | KUBEVIRT_POD_CREATED, event.newValue().value()))); |
| 331 | break; |
| 332 | case UPDATE: |
| 333 | log.debug("Kubernetes pod updated {}", event.newValue()); |
| 334 | eventExecutor.execute(() -> processUpdate(event)); |
| 335 | break; |
| 336 | case REMOVE: |
| 337 | log.debug("Kubernetes pod removed {}", event.oldValue()); |
| 338 | eventExecutor.execute(() -> |
| 339 | notifyDelegate(new KubevirtPodEvent( |
| 340 | KUBEVIRT_POD_REMOVED, event.oldValue().value()))); |
| 341 | break; |
| 342 | default: |
| 343 | // do nothing |
| 344 | break; |
| 345 | } |
| 346 | } |
| 347 | |
| 348 | private void processUpdate(MapEvent<String, Pod> event) { |
| 349 | notifyDelegate(new KubevirtPodEvent( |
| 350 | KUBEVIRT_POD_UPDATED, event.newValue().value())); |
| 351 | |
| 352 | String oldPhase = event.oldValue().value().getStatus().getPhase(); |
| 353 | String newPhase = event.newValue().value().getStatus().getPhase(); |
| 354 | |
| 355 | if (!PENDING.equals(oldPhase) && PENDING.equals(newPhase)) { |
| 356 | notifyDelegate(new KubevirtPodEvent( |
| 357 | KUBEVIRT_POD_PENDING, event.newValue().value())); |
| 358 | } |
| 359 | |
| 360 | if (!RUNNING.equals(oldPhase) && RUNNING.equals(newPhase)) { |
| 361 | notifyDelegate(new KubevirtPodEvent( |
| 362 | KUBEVIRT_POD_RUNNING, event.newValue().value())); |
| 363 | } |
| 364 | |
| 365 | if (!SUCCEEDED.equals(oldPhase) && SUCCEEDED.equals(newPhase)) { |
| 366 | notifyDelegate(new KubevirtPodEvent( |
| 367 | KUBEVIRT_POD_SUCCEEDED, event.newValue().value())); |
| 368 | } |
| 369 | |
| 370 | if (!FAILED.equals(oldPhase) && FAILED.equals(newPhase)) { |
| 371 | notifyDelegate(new KubevirtPodEvent( |
| 372 | KUBEVIRT_POD_FAILED, event.newValue().value())); |
| 373 | } |
| 374 | |
| 375 | if (!UNKNOWN.equals(oldPhase) && UNKNOWN.equals(newPhase)) { |
| 376 | notifyDelegate(new KubevirtPodEvent( |
| 377 | KUBEVIRT_POD_UNKNOWN, event.newValue().value())); |
| 378 | } |
| 379 | |
| 380 | if (!COMPLETED.equals(oldPhase) && COMPLETED.equals(newPhase)) { |
| 381 | notifyDelegate(new KubevirtPodEvent( |
| 382 | KUBEVIRT_POD_COMPLETED, event.newValue().value())); |
| 383 | } |
| 384 | |
| 385 | if (!CRASH_LOOP_BACK_OFF.equals(oldPhase) && CRASH_LOOP_BACK_OFF.equals(newPhase)) { |
| 386 | notifyDelegate(new KubevirtPodEvent( |
| 387 | KUBEVIRT_POD_CRASH_LOOP_BACK_OFF, event.newValue().value())); |
| 388 | } |
| 389 | |
| 390 | Map<String, String> oldAnnot = event.oldValue().value().getMetadata().getAnnotations(); |
| 391 | Map<String, String> newAnnot = event.newValue().value().getMetadata().getAnnotations(); |
| 392 | |
| 393 | if (oldAnnot == null && newAnnot != null) { |
| 394 | notifyDelegate(new KubevirtPodEvent( |
| 395 | KUBEVIRT_POD_ANNOTATION_ADDED, event.newValue().value())); |
| 396 | } |
| 397 | } |
| 398 | } |
| 399 | } |