diff --git a/api/openapi-spec/swagger.json b/api/openapi-spec/swagger.json index 235bc3089c50..930a5998096f 100644 --- a/api/openapi-spec/swagger.json +++ b/api/openapi-spec/swagger.json @@ -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", @@ -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", @@ -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" }, diff --git a/manifests/generated/kv-resource.yaml b/manifests/generated/kv-resource.yaml index 5991df3a98d8..8b1f12af31c4 100644 --- a/manifests/generated/kv-resource.yaml +++ b/manifests/generated/kv-resource.yaml @@ -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 @@ -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 diff --git a/pkg/virt-operator/resource/apply/generations.go b/pkg/virt-operator/resource/apply/generations.go index 16b8bb42a0fe..fac50a1970c7 100644 --- a/pkg/virt-operator/resource/apply/generations.go +++ b/pkg/virt-operator/resource/apply/generations.go @@ -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" @@ -45,14 +47,16 @@ 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 } @@ -60,7 +64,8 @@ func GetExpectedGeneration(required runtime.Object, previousGenerations []operat return generation.LastGeneration } -func SetGeneration(generations *[]operatorsv1.GenerationStatus, actual runtime.Object) { +func SetGeneration(generations *[]k6tv1.GenerationStatus, actual runtime.Object) { + if actual == nil { return } @@ -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 } diff --git a/pkg/virt-operator/resource/generate/components/validations_generated.go b/pkg/virt-operator/resource/generate/components/validations_generated.go index 3081ba90ce9b..2645e6567ff8 100644 --- a/pkg/virt-operator/resource/generate/components/validations_generated.go +++ b/pkg/virt-operator/resource/generate/components/validations_generated.go @@ -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 diff --git a/staging/src/kubevirt.io/client-go/api/v1/BUILD.bazel b/staging/src/kubevirt.io/client-go/api/v1/BUILD.bazel index c545910875af..f1a26d98fee5 100644 --- a/staging/src/kubevirt.io/client-go/api/v1/BUILD.bazel +++ b/staging/src/kubevirt.io/client-go/api/v1/BUILD.bazel @@ -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", diff --git a/staging/src/kubevirt.io/client-go/api/v1/deepcopy_generated.go b/staging/src/kubevirt.io/client-go/api/v1/deepcopy_generated.go index 0cac5088b39d..ed7792280f49 100644 --- a/staging/src/kubevirt.io/client-go/api/v1/deepcopy_generated.go +++ b/staging/src/kubevirt.io/client-go/api/v1/deepcopy_generated.go @@ -21,7 +21,6 @@ limitations under the License. package v1 import ( - operatorv1 "github.com/openshift/api/operator/v1" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" runtime "k8s.io/apimachinery/pkg/runtime" @@ -1305,6 +1304,22 @@ func (in *GPU) DeepCopy() *GPU { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *GenerationStatus) DeepCopyInto(out *GenerationStatus) { + *out = *in + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new GenerationStatus. +func (in *GenerationStatus) DeepCopy() *GenerationStatus { + if in == nil { + return nil + } + out := new(GenerationStatus) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *GuestAgentCommandInfo) DeepCopyInto(out *GuestAgentCommandInfo) { *out = *in @@ -1947,7 +1962,7 @@ func (in *KubeVirtStatus) DeepCopyInto(out *KubeVirtStatus) { } if in.Generations != nil { in, out := &in.Generations, &out.Generations - *out = make([]operatorv1.GenerationStatus, len(*in)) + *out = make([]GenerationStatus, len(*in)) copy(*out, *in) } return diff --git a/staging/src/kubevirt.io/client-go/api/v1/openapi_generated.go b/staging/src/kubevirt.io/client-go/api/v1/openapi_generated.go index 49771370b3d0..e268003fcaf2 100644 --- a/staging/src/kubevirt.io/client-go/api/v1/openapi_generated.go +++ b/staging/src/kubevirt.io/client-go/api/v1/openapi_generated.go @@ -438,6 +438,7 @@ func GetOpenAPIDefinitions(ref common.ReferenceCallback) map[string]common.OpenA "kubevirt.io/client-go/api/v1.Firmware": schema_kubevirtio_client_go_api_v1_Firmware(ref), "kubevirt.io/client-go/api/v1.FloppyTarget": schema_kubevirtio_client_go_api_v1_FloppyTarget(ref), "kubevirt.io/client-go/api/v1.GPU": schema_kubevirtio_client_go_api_v1_GPU(ref), + "kubevirt.io/client-go/api/v1.GenerationStatus": schema_kubevirtio_client_go_api_v1_GenerationStatus(ref), "kubevirt.io/client-go/api/v1.GuestAgentCommandInfo": schema_kubevirtio_client_go_api_v1_GuestAgentCommandInfo(ref), "kubevirt.io/client-go/api/v1.HPETTimer": schema_kubevirtio_client_go_api_v1_HPETTimer(ref), "kubevirt.io/client-go/api/v1.HostDevice": schema_kubevirtio_client_go_api_v1_HostDevice(ref), @@ -20553,6 +20554,62 @@ func schema_kubevirtio_client_go_api_v1_GPU(ref common.ReferenceCallback) common } } +func schema_kubevirtio_client_go_api_v1_GenerationStatus(ref common.ReferenceCallback) common.OpenAPIDefinition { + return common.OpenAPIDefinition{ + Schema: spec.Schema{ + SchemaProps: spec.SchemaProps{ + Description: "GenerationStatus keeps track of the generation for a given resource so that decisions about forced updates can be made.", + Type: []string{"object"}, + Properties: map[string]spec.Schema{ + "group": { + SchemaProps: spec.SchemaProps{ + Description: "group is the group of the thing you're tracking", + Type: []string{"string"}, + Format: "", + }, + }, + "resource": { + SchemaProps: spec.SchemaProps{ + Description: "resource is the resource type of the thing you're tracking", + Type: []string{"string"}, + Format: "", + }, + }, + "namespace": { + SchemaProps: spec.SchemaProps{ + Description: "namespace is where the thing you're tracking is", + Type: []string{"string"}, + Format: "", + }, + }, + "name": { + SchemaProps: spec.SchemaProps{ + Description: "name is the name of the thing you're tracking", + Type: []string{"string"}, + Format: "", + }, + }, + "lastGeneration": { + SchemaProps: spec.SchemaProps{ + Description: "lastGeneration is the last generation of the workload controller involved", + Type: []string{"integer"}, + Format: "int64", + }, + }, + "hash": { + SchemaProps: spec.SchemaProps{ + Description: "hash is an optional field set for resources without generation that are content sensitive like secrets and configmaps", + Type: []string{"string"}, + Format: "", + }, + }, + }, + Required: []string{"group", "resource", "name", "lastGeneration"}, + }, + }, + } +} + func schema_kubevirtio_client_go_api_v1_GuestAgentCommandInfo(ref common.ReferenceCallback) common.OpenAPIDefinition { return common.OpenAPIDefinition{ Schema: spec.Schema{ @@ -21564,7 +21621,7 @@ func schema_kubevirtio_client_go_api_v1_KubeVirtStatus(ref common.ReferenceCallb Items: &spec.SchemaOrArray{ Schema: &spec.Schema{ SchemaProps: spec.SchemaProps{ - Ref: ref("github.com/openshift/api/operator/v1.GenerationStatus"), + Ref: ref("kubevirt.io/client-go/api/v1.GenerationStatus"), }, }, }, @@ -21574,7 +21631,7 @@ func schema_kubevirtio_client_go_api_v1_KubeVirtStatus(ref common.ReferenceCallb }, }, Dependencies: []string{ - "github.com/openshift/api/operator/v1.GenerationStatus", "kubevirt.io/client-go/api/v1.KubeVirtCondition"}, + "kubevirt.io/client-go/api/v1.GenerationStatus", "kubevirt.io/client-go/api/v1.KubeVirtCondition"}, } } diff --git a/staging/src/kubevirt.io/client-go/api/v1/types.go b/staging/src/kubevirt.io/client-go/api/v1/types.go index 4f6ef972df3f..1dbc171f04ad 100644 --- a/staging/src/kubevirt.io/client-go/api/v1/types.go +++ b/staging/src/kubevirt.io/client-go/api/v1/types.go @@ -38,8 +38,6 @@ import ( "k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/apimachinery/pkg/types" - operatorsv1 "github.com/openshift/api/operator/v1" - cdiv1 "kubevirt.io/containerized-data-importer/pkg/apis/core/v1alpha1" ) @@ -1502,6 +1500,26 @@ const ( KubeVirtUninstallStrategyBlockUninstallIfWorkloadsExist KubeVirtUninstallStrategy = "BlockUninstallIfWorkloadsExist" ) +// GenerationStatus keeps track of the generation for a given resource so that decisions about forced updates can be made. +// +// +k8s:openapi-gen=true +type GenerationStatus struct { + // group is the group of the thing you're tracking + Group string `json:"group"` + // resource is the resource type of the thing you're tracking + Resource string `json:"resource"` + // namespace is where the thing you're tracking is + // +optional + Namespace string `json:"namespace,omitempty" optional:"true"` + // name is the name of the thing you're tracking + Name string `json:"name"` + // lastGeneration is the last generation of the workload controller involved + LastGeneration int64 `json:"lastGeneration"` + // hash is an optional field set for resources without generation that are content sensitive like secrets and configmaps + // +optional + Hash string `json:"hash,omitempty" optional:"true"` +} + // KubeVirtStatus represents information pertaining to a KubeVirt deployment. // // +k8s:openapi-gen=true @@ -1519,7 +1537,7 @@ type KubeVirtStatus struct { ObservedDeploymentID string `json:"observedDeploymentID,omitempty" optional:"true"` OutdatedVirtualMachineInstanceWorkloads *int `json:"outdatedVirtualMachineInstanceWorkloads,omitempty" optional:"true"` // +listType=atomic - Generations []operatorsv1.GenerationStatus `json:"generations,omitempty" optional:"true"` + Generations []GenerationStatus `json:"generations,omitempty" optional:"true"` } // KubeVirtPhase is a label for the phase of a KubeVirt deployment at the current time. diff --git a/staging/src/kubevirt.io/client-go/api/v1/types_swagger_generated.go b/staging/src/kubevirt.io/client-go/api/v1/types_swagger_generated.go index 2ef31f9f9c1b..ee6cb9b72143 100644 --- a/staging/src/kubevirt.io/client-go/api/v1/types_swagger_generated.go +++ b/staging/src/kubevirt.io/client-go/api/v1/types_swagger_generated.go @@ -424,6 +424,18 @@ func (CustomizeComponentsPatch) SwaggerDoc() map[string]string { } } +func (GenerationStatus) SwaggerDoc() map[string]string { + return map[string]string{ + "": "GenerationStatus keeps track of the generation for a given resource so that decisions about forced updates can be made.\n\n+k8s:openapi-gen=true", + "group": "group is the group of the thing you're tracking", + "resource": "resource is the resource type of the thing you're tracking", + "namespace": "namespace is where the thing you're tracking is\n+optional", + "name": "name is the name of the thing you're tracking", + "lastGeneration": "lastGeneration is the last generation of the workload controller involved", + "hash": "hash is an optional field set for resources without generation that are content sensitive like secrets and configmaps\n+optional", + } +} + func (KubeVirtStatus) SwaggerDoc() map[string]string { return map[string]string{ "": "KubeVirtStatus represents information pertaining to a KubeVirt deployment.\n\n+k8s:openapi-gen=true", diff --git a/staging/src/kubevirt.io/client-go/apis/snapshot/v1alpha1/openapi_generated.go b/staging/src/kubevirt.io/client-go/apis/snapshot/v1alpha1/openapi_generated.go index 99f53bc6c0ad..e6674f539125 100644 --- a/staging/src/kubevirt.io/client-go/apis/snapshot/v1alpha1/openapi_generated.go +++ b/staging/src/kubevirt.io/client-go/apis/snapshot/v1alpha1/openapi_generated.go @@ -336,6 +336,7 @@ func GetOpenAPIDefinitions(ref common.ReferenceCallback) map[string]common.OpenA "kubevirt.io/client-go/api/v1.Firmware": schema_kubevirtio_client_go_api_v1_Firmware(ref), "kubevirt.io/client-go/api/v1.FloppyTarget": schema_kubevirtio_client_go_api_v1_FloppyTarget(ref), "kubevirt.io/client-go/api/v1.GPU": schema_kubevirtio_client_go_api_v1_GPU(ref), + "kubevirt.io/client-go/api/v1.GenerationStatus": schema_kubevirtio_client_go_api_v1_GenerationStatus(ref), "kubevirt.io/client-go/api/v1.GuestAgentCommandInfo": schema_kubevirtio_client_go_api_v1_GuestAgentCommandInfo(ref), "kubevirt.io/client-go/api/v1.HPETTimer": schema_kubevirtio_client_go_api_v1_HPETTimer(ref), "kubevirt.io/client-go/api/v1.HostDevice": schema_kubevirtio_client_go_api_v1_HostDevice(ref), @@ -15637,6 +15638,62 @@ func schema_kubevirtio_client_go_api_v1_GPU(ref common.ReferenceCallback) common } } +func schema_kubevirtio_client_go_api_v1_GenerationStatus(ref common.ReferenceCallback) common.OpenAPIDefinition { + return common.OpenAPIDefinition{ + Schema: spec.Schema{ + SchemaProps: spec.SchemaProps{ + Description: "GenerationStatus keeps track of the generation for a given resource so that decisions about forced updates can be made.", + Type: []string{"object"}, + Properties: map[string]spec.Schema{ + "group": { + SchemaProps: spec.SchemaProps{ + Description: "group is the group of the thing you're tracking", + Type: []string{"string"}, + Format: "", + }, + }, + "resource": { + SchemaProps: spec.SchemaProps{ + Description: "resource is the resource type of the thing you're tracking", + Type: []string{"string"}, + Format: "", + }, + }, + "namespace": { + SchemaProps: spec.SchemaProps{ + Description: "namespace is where the thing you're tracking is", + Type: []string{"string"}, + Format: "", + }, + }, + "name": { + SchemaProps: spec.SchemaProps{ + Description: "name is the name of the thing you're tracking", + Type: []string{"string"}, + Format: "", + }, + }, + "lastGeneration": { + SchemaProps: spec.SchemaProps{ + Description: "lastGeneration is the last generation of the workload controller involved", + Type: []string{"integer"}, + Format: "int64", + }, + }, + "hash": { + SchemaProps: spec.SchemaProps{ + Description: "hash is an optional field set for resources without generation that are content sensitive like secrets and configmaps", + Type: []string{"string"}, + Format: "", + }, + }, + }, + Required: []string{"group", "resource", "name", "lastGeneration"}, + }, + }, + } +} + func schema_kubevirtio_client_go_api_v1_GuestAgentCommandInfo(ref common.ReferenceCallback) common.OpenAPIDefinition { return common.OpenAPIDefinition{ Schema: spec.Schema{ @@ -16648,7 +16705,7 @@ func schema_kubevirtio_client_go_api_v1_KubeVirtStatus(ref common.ReferenceCallb Items: &spec.SchemaOrArray{ Schema: &spec.Schema{ SchemaProps: spec.SchemaProps{ - Ref: ref("github.com/openshift/api/operator/v1.GenerationStatus"), + Ref: ref("kubevirt.io/client-go/api/v1.GenerationStatus"), }, }, }, @@ -16658,7 +16715,7 @@ func schema_kubevirtio_client_go_api_v1_KubeVirtStatus(ref common.ReferenceCallb }, }, Dependencies: []string{ - "github.com/openshift/api/operator/v1.GenerationStatus", "kubevirt.io/client-go/api/v1.KubeVirtCondition"}, + "kubevirt.io/client-go/api/v1.GenerationStatus", "kubevirt.io/client-go/api/v1.KubeVirtCondition"}, } } diff --git a/staging/src/kubevirt.io/client-go/go.mod b/staging/src/kubevirt.io/client-go/go.mod index ecdf9b09ad23..ada423f68d7e 100644 --- a/staging/src/kubevirt.io/client-go/go.mod +++ b/staging/src/kubevirt.io/client-go/go.mod @@ -14,7 +14,6 @@ require ( github.com/kubernetes-csi/external-snapshotter/v2 v2.1.1 github.com/onsi/ginkgo v1.12.1 github.com/onsi/gomega v1.10.1 - github.com/openshift/api v0.0.0 github.com/openshift/client-go v0.0.0 github.com/pborman/uuid v1.2.0 github.com/spf13/pflag v1.0.5