Skip to content

Commit

Permalink
pick the most recent install strategy matching the version/registry
Browse files Browse the repository at this point in the history
Signed-off-by: David Vossel <[email protected]>
  • Loading branch information
davidvossel committed Mar 8, 2019
1 parent 21060d4 commit 8377063
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 10 deletions.
27 changes: 17 additions & 10 deletions pkg/virt-operator/install-strategy/strategy.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,22 @@ func GenerateCurrentInstallStrategy(namespace string,
return strategy, nil
}

func mostRecentConfigMap(configMaps []*corev1.ConfigMap) *corev1.ConfigMap {
var configMap *corev1.ConfigMap
// choose the most recent configmap if multiple match.
mostRecentTime := metav1.Time{}
for _, config := range configMaps {
if configMap == nil {
configMap = config
mostRecentTime = config.ObjectMeta.CreationTimestamp
} else if mostRecentTime.Before(&config.ObjectMeta.CreationTimestamp) {
configMap = config
mostRecentTime = config.ObjectMeta.CreationTimestamp
}
}
return configMap
}

func LoadInstallStrategyFromCache(stores util.Stores, namespace string, imageTag string, imageRegistry string) (*InstallStrategy, error) {
var configMap *corev1.ConfigMap
var matchingConfigMaps []*corev1.ConfigMap
Expand All @@ -292,16 +308,7 @@ func LoadInstallStrategyFromCache(stores util.Stores, namespace string, imageTag
}

// choose the most recent configmap if multiple match.
mostRecentTime := metav1.Time{}
for _, config := range matchingConfigMaps {
if configMap == nil {
configMap = config
mostRecentTime = config.ObjectMeta.CreationTimestamp
} else if mostRecentTime.Before(&config.ObjectMeta.CreationTimestamp) {
configMap = config
mostRecentTime = config.ObjectMeta.CreationTimestamp
}
}
configMap = mostRecentConfigMap(matchingConfigMaps)

data, ok := configMap.Data["manifests"]
if !ok {
Expand Down
29 changes: 29 additions & 0 deletions pkg/virt-operator/install-strategy/strategy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
corev1 "k8s.io/api/core/v1"
rbacv1 "k8s.io/api/rbac/v1"
extv1beta1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

var _ = Describe("Install Strategy", func() {
Expand Down Expand Up @@ -154,4 +155,32 @@ var _ = Describe("Install Strategy", func() {
}
})
})

Context("should match", func() {
It("the most recent install strategy.", func() {
var configMaps []*corev1.ConfigMap

configMaps = append(configMaps, &corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Name: "test1",
CreationTimestamp: metav1.Time{},
},
})
configMaps = append(configMaps, &corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Name: "test2",
CreationTimestamp: metav1.Now(),
},
})
configMaps = append(configMaps, &corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Name: "test3",
CreationTimestamp: metav1.Time{},
},
})

configMap := mostRecentConfigMap(configMaps)
Expect(configMap.Name).To(Equal("test2"))
})
})
})

0 comments on commit 8377063

Please sign in to comment.