forked from kubevirt/kubevirt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
strategy.go
51 lines (42 loc) · 1.6 KB
/
strategy.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package virt_operator
import (
"context"
"fmt"
k8sv1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"kubevirt.io/client-go/log"
install "kubevirt.io/kubevirt/pkg/virt-operator/resource/generate/install"
operatorutil "kubevirt.io/kubevirt/pkg/virt-operator/util"
)
func (c *KubeVirtController) getCachedInstallStrategy(config *operatorutil.KubeVirtDeploymentConfig, generation int64) (*install.Strategy, bool) {
cachedValue := c.latestStrategy.Load()
if cachedValue == nil {
return nil, false
}
cachedEntry, ok := cachedValue.(strategyCacheEntry)
if !ok {
return nil, ok
}
if cachedEntry.key == fmt.Sprintf(installStrategyKeyTemplate, config.GetDeploymentID(), generation) {
return cachedEntry.value, true
}
return nil, false
}
func (c *KubeVirtController) cacheInstallStrategy(cachedEntry *install.Strategy, config *operatorutil.KubeVirtDeploymentConfig, generation int64) {
c.latestStrategy.Store(strategyCacheEntry{key: fmt.Sprintf(installStrategyKeyTemplate, config.GetDeploymentID(), generation), value: cachedEntry})
}
func (c *KubeVirtController) deleteAllInstallStrategy() error {
for _, obj := range c.stores.InstallStrategyConfigMapCache.List() {
configMap, ok := obj.(*k8sv1.ConfigMap)
if ok && configMap.DeletionTimestamp == nil {
err := c.clientset.CoreV1().ConfigMaps(configMap.Namespace).Delete(context.Background(), configMap.Name, metav1.DeleteOptions{})
if err != nil {
log.Log.Errorf("Failed to delete configmap %+v: %v", configMap, err)
return err
}
}
}
// reset the cached strategy
c.latestStrategy.Store(strategyCacheEntry{})
return nil
}