Skip to content

Commit

Permalink
Map api version of generation info to openshift version
Browse files Browse the repository at this point in the history
Signed-off-by: Roman Mohr <[email protected]>
  • Loading branch information
rmohr authored and kubevirt-bot committed May 11, 2021
1 parent b0fceb7 commit 1db0154
Showing 1 changed file with 49 additions and 4 deletions.
53 changes: 49 additions & 4 deletions pkg/virt-operator/resource/apply/generations.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (

"k8s.io/apimachinery/pkg/runtime"

k6tv1 "kubevirt.io/client-go/api/v1"

appsv1 "k8s.io/api/apps/v1"

operatorsv1 "github.com/openshift/api/operator/v1"
Expand Down Expand Up @@ -45,22 +47,25 @@ func getGroupResource(required runtime.Object) (group string, resource string, e
return
}

func GetExpectedGeneration(required runtime.Object, previousGenerations []operatorsv1.GenerationStatus) int64 {
func GetExpectedGeneration(required runtime.Object, previousGenerations []k6tv1.GenerationStatus) int64 {
group, resource, err := getGroupResource(required)
if err != nil {
return -1
}

operatorGenerations := toOperatorGenerations(previousGenerations)

meta := required.(v1.Object)
generation := resourcemerge.GenerationFor(previousGenerations, schema.GroupResource{Group: group, Resource: resource}, meta.GetNamespace(), meta.GetName())
generation := resourcemerge.GenerationFor(operatorGenerations, schema.GroupResource{Group: group, Resource: resource}, meta.GetNamespace(), meta.GetName())
if generation == nil {
return -1
}

return generation.LastGeneration
}

func SetGeneration(generations *[]operatorsv1.GenerationStatus, actual runtime.Object) {
func SetGeneration(generations *[]k6tv1.GenerationStatus, actual runtime.Object) {

if actual == nil {
return
}
Expand All @@ -70,13 +75,53 @@ func SetGeneration(generations *[]operatorsv1.GenerationStatus, actual runtime.O
return
}

operatorGenerations := toOperatorGenerations(*generations)
meta := actual.(v1.Object)

resourcemerge.SetGeneration(generations, operatorsv1.GenerationStatus{
resourcemerge.SetGeneration(&operatorGenerations, operatorsv1.GenerationStatus{
Group: group,
Resource: resource,
Namespace: meta.GetNamespace(),
Name: meta.GetName(),
LastGeneration: meta.GetGeneration(),
})

newGenerations := toAPIGenerations(operatorGenerations)
*generations = newGenerations
}

func toOperatorGeneration(generation k6tv1.GenerationStatus) operatorsv1.GenerationStatus {
return operatorsv1.GenerationStatus{
Group: generation.Group,
Resource: generation.Resource,
Namespace: generation.Namespace,
Name: generation.Name,
LastGeneration: generation.LastGeneration,
Hash: generation.Hash,
}
}

func toAPIGeneration(generation operatorsv1.GenerationStatus) k6tv1.GenerationStatus {
return k6tv1.GenerationStatus{
Group: generation.Group,
Resource: generation.Resource,
Namespace: generation.Namespace,
Name: generation.Name,
LastGeneration: generation.LastGeneration,
Hash: generation.Hash,
}
}

func toOperatorGenerations(generations []k6tv1.GenerationStatus) (operatorGenerations []operatorsv1.GenerationStatus) {
for _, generation := range generations {
operatorGenerations = append(operatorGenerations, toOperatorGeneration(generation))
}
return operatorGenerations
}

func toAPIGenerations(generations []operatorsv1.GenerationStatus) (apiGenerations []k6tv1.GenerationStatus) {
for _, generation := range generations {
apiGenerations = append(apiGenerations, toAPIGeneration(generation))
}
return apiGenerations
}

0 comments on commit 1db0154

Please sign in to comment.