Skip to content

Commit

Permalink
Merge pull request kubevirt#5633 from kubevirt-bot/cherry-pick-5609-t…
Browse files Browse the repository at this point in the history
…o-release-0.41

[release-0.41] Fixes olm schema validation for the KubeVirt CR api
  • Loading branch information
kubevirt-bot authored May 11, 2021
2 parents c8a5db3 + 1db0154 commit b7f3224
Show file tree
Hide file tree
Showing 11 changed files with 270 additions and 55 deletions.
78 changes: 38 additions & 40 deletions api/openapi-spec/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -7862,45 +7862,6 @@
}
},
"definitions": {
"github.com.openshift.api.operator.v1.GenerationStatus": {
"description": "GenerationStatus keeps track of the generation for a given resource so that decisions about forced updates can be made.",
"type": "object",
"required": [
"group",
"resource",
"namespace",
"name",
"lastGeneration",
"hash"
],
"properties": {
"group": {
"description": "group is the group of the thing you're tracking",
"type": "string"
},
"hash": {
"description": "hash is an optional field set for resources without generation that are content sensitive like secrets and configmaps",
"type": "string"
},
"lastGeneration": {
"description": "lastGeneration is the last generation of the workload controller involved",
"type": "integer",
"format": "int64"
},
"name": {
"description": "name is the name of the thing you're tracking",
"type": "string"
},
"namespace": {
"description": "namespace is where the thing you're tracking is",
"type": "string"
},
"resource": {
"description": "resource is the resource type of the thing you're tracking",
"type": "string"
}
}
},
"k8s.io.api.core.v1.Affinity": {
"description": "Affinity is a group of affinity scheduling rules.",
"type": "object",
Expand Down Expand Up @@ -10029,6 +9990,43 @@
}
}
},
"v1.GenerationStatus": {
"description": "GenerationStatus keeps track of the generation for a given resource so that decisions about forced updates can be made.",
"type": "object",
"required": [
"group",
"resource",
"name",
"lastGeneration"
],
"properties": {
"group": {
"description": "group is the group of the thing you're tracking",
"type": "string"
},
"hash": {
"description": "hash is an optional field set for resources without generation that are content sensitive like secrets and configmaps",
"type": "string"
},
"lastGeneration": {
"description": "lastGeneration is the last generation of the workload controller involved",
"type": "integer",
"format": "int64"
},
"name": {
"description": "name is the name of the thing you're tracking",
"type": "string"
},
"namespace": {
"description": "namespace is where the thing you're tracking is",
"type": "string"
},
"resource": {
"description": "resource is the resource type of the thing you're tracking",
"type": "string"
}
}
},
"v1.GuestAgentCommandInfo": {
"description": "List of commands that QEMU guest agent supports",
"type": "object",
Expand Down Expand Up @@ -10517,7 +10515,7 @@
"generations": {
"type": "array",
"items": {
"$ref": "#/definitions/github.com.openshift.api.operator.v1.GenerationStatus"
"$ref": "#/definitions/v1.GenerationStatus"
},
"x-kubernetes-list-type": "atomic"
},
Expand Down
10 changes: 10 additions & 0 deletions manifests/generated/kv-resource.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1112,6 +1112,11 @@ spec:
resource:
description: resource is the resource type of the thing you're tracking
type: string
required:
- group
- lastGeneration
- name
- resource
type: object
type: array
x-kubernetes-list-type: atomic
Expand Down Expand Up @@ -2240,6 +2245,11 @@ spec:
resource:
description: resource is the resource type of the thing you're tracking
type: string
required:
- group
- lastGeneration
- name
- resource
type: object
type: array
x-kubernetes-list-type: atomic
Expand Down
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
}
Original file line number Diff line number Diff line change
Expand Up @@ -1334,6 +1334,11 @@ var CRDsValidation map[string]string = map[string]string{
resource:
description: resource is the resource type of the thing you're tracking
type: string
required:
- group
- lastGeneration
- name
- resource
type: object
type: array
x-kubernetes-list-type: atomic
Expand Down
1 change: 0 additions & 1 deletion staging/src/kubevirt.io/client-go/api/v1/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ go_library(
deps = [
"//staging/src/kubevirt.io/client-go/precond:go_default_library",
"//vendor/github.com/go-openapi/spec:go_default_library",
"//vendor/github.com/openshift/api/operator/v1:go_default_library",
"//vendor/github.com/pborman/uuid:go_default_library",
"//vendor/k8s.io/api/core/v1:go_default_library",
"//vendor/k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1:go_default_library",
Expand Down
19 changes: 17 additions & 2 deletions staging/src/kubevirt.io/client-go/api/v1/deepcopy_generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

61 changes: 59 additions & 2 deletions staging/src/kubevirt.io/client-go/api/v1/openapi_generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit b7f3224

Please sign in to comment.