Skip to content

Commit

Permalink
Merge pull request vmware-tanzu#720 from abaruni/topic/badnan/VMSVC-2105
Browse files Browse the repository at this point in the history
🌱 Update StoragePolicyQuota to consume v1alpha2
  • Loading branch information
akutz authored Sep 20, 2024
2 parents 82ce71c + f430e5f commit 84365f4
Show file tree
Hide file tree
Showing 19 changed files with 1,034 additions and 29 deletions.
140 changes: 140 additions & 0 deletions config/crd/external-crds/cns.vmware.com_storagepolicyquotas.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,146 @@ spec:
type: object
type: object
served: true
storage: false
subresources:
status: {}
- name: v1alpha2
schema:
openAPIV3Schema:
description: StoragePolicyQuota is the Schema for the storagepolicyquotas
API
properties:
apiVersion:
description: |-
APIVersion defines the versioned schema of this representation of an object.
Servers should convert recognized schemas to the latest internal value, and
may reject unrecognized values.
More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources
type: string
kind:
description: |-
Kind is a string value representing the REST resource this object represents.
Servers may infer this from the endpoint the client submits requests to.
Cannot be updated.
In CamelCase.
More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds
type: string
metadata:
type: object
spec:
description: StoragePolicyQuotaSpec defines the desired state of StoragePolicyQuota
properties:
limit:
anyOf:
- type: integer
- type: string
description: |-
Total limit of storage across all types of storage resources
for given storage policy within given namespace
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
x-kubernetes-int-or-string: true
storagePolicyId:
description: ID of the storage policy
maxLength: 128
type: string
x-kubernetes-validations:
- message: StoragePolicyId is immutable
rule: self == oldSelf
required:
- storagePolicyId
type: object
status:
description: StoragePolicyQuotaStatus defines the observed state of StoragePolicyQuota
properties:
extensions:
description: Storage quota usage details per storage object type for
given storage policy
items:
properties:
extensionName:
description: Name of service extension associated with resource
kind to be provisioned
maxLength: 64
type: string
extensionQuotaUsage:
description: Storage usage details per storage class level for
given object kind
items:
description: SCLevelQuotaStatus gives storage quota usage
per Kubernetes storage class
properties:
scQuotaUsage:
description: Storage quota usage details for given Kubernetes
storage class
properties:
reserved:
anyOf:
- type: integer
- type: string
description: Storage quota that is reserved for storage
resource(s) that are being provisioned
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
x-kubernetes-int-or-string: true
used:
anyOf:
- type: integer
- type: string
description: Storage quota that is already used by
storage resource(s) that have been provisioned
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
x-kubernetes-int-or-string: true
type: object
storageClassName:
description: Name of the Kubernetes StorageClass
maxLength: 64
type: string
required:
- storageClassName
type: object
type: array
required:
- extensionName
type: object
type: array
total:
description: Storage quota usage details per storage class level for
given storage policy
items:
description: SCLevelQuotaStatus gives storage quota usage per Kubernetes
storage class
properties:
scQuotaUsage:
description: Storage quota usage details for given Kubernetes
storage class
properties:
reserved:
anyOf:
- type: integer
- type: string
description: Storage quota that is reserved for storage
resource(s) that are being provisioned
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
x-kubernetes-int-or-string: true
used:
anyOf:
- type: integer
- type: string
description: Storage quota that is already used by storage
resource(s) that have been provisioned
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
x-kubernetes-int-or-string: true
type: object
storageClassName:
description: Name of the Kubernetes StorageClass
maxLength: 64
type: string
required:
- storageClassName
type: object
type: array
type: object
type: object
served: true
storage: true
subresources:
status: {}
112 changes: 112 additions & 0 deletions config/crd/external-crds/cns.vmware.com_storagepolicyusages.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,116 @@ spec:
type: object
type: object
served: true
storage: false
- name: v1alpha2
schema:
openAPIV3Schema:
description: StoragePolicyUsage is the Schema for the storagepolicyusages
API
properties:
apiVersion:
description: |-
APIVersion defines the versioned schema of this representation of an object.
Servers should convert recognized schemas to the latest internal value, and
may reject unrecognized values.
More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources
type: string
kind:
description: |-
Kind is a string value representing the REST resource this object represents.
Servers may infer this from the endpoint the client submits requests to.
Cannot be updated.
In CamelCase.
More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds
type: string
metadata:
type: object
spec:
description: StoragePolicyUsageSpec defines the desired state of StoragePolicyUsage
properties:
caBundle:
description: caBundle is a PEM encoded CA bundle which will be used
to validate the extension service's server certificate.
format: byte
type: string
resourceApiGroup:
description: |-
APIGroup is the group for the resource being referenced.
If it is not specified, the specified ResourceKind must be in the core API group.
For resources not in the core API group, this field is required.
type: string
x-kubernetes-validations:
- message: ResourceAPIgroup is immutable
rule: self == oldSelf
resourceExtensionName:
description: Name of service extension for given storage resource
type
type: string
x-kubernetes-validations:
- message: ResourceExtensionName is immutable
rule: self == oldSelf
resourceExtensionNamespace:
description: Namespace of service extension for given storage resource
type
type: string
x-kubernetes-validations:
- message: ResourceExtensionNamespace is immutable
rule: self == oldSelf
resourceKind:
description: Type of resource being referenced
maxLength: 64
type: string
x-kubernetes-validations:
- message: ResourceKind is immutable
rule: self == oldSelf
storageClassName:
description: name of K8S storage class associated with given storage
policy
maxLength: 64
type: string
x-kubernetes-validations:
- message: StorageClassName is immutable
rule: self == oldSelf
storagePolicyId:
description: ID of the storage policy
maxLength: 128
type: string
x-kubernetes-validations:
- message: StoragePolicyId is immutable
rule: self == oldSelf
required:
- resourceExtensionName
- resourceKind
- storageClassName
- storagePolicyId
type: object
status:
description: StoragePolicyUsageStatus defines the observed state of StoragePolicyUsage
properties:
quotaUsage:
description: Storage usage details per storage object type for given
storage policy
properties:
reserved:
anyOf:
- type: integer
- type: string
description: Storage quota that is reserved for storage resource(s)
that are being provisioned
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
x-kubernetes-int-or-string: true
used:
anyOf:
- type: integer
- type: string
description: Storage quota that is already used by storage resource(s)
that have been provisioned
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
x-kubernetes-int-or-string: true
type: object
type: object
type: object
served: true
storage: true
subresources:
status: {}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/manager"

vmopv1 "github.com/vmware-tanzu/vm-operator/api/v1alpha3"
spqv1 "github.com/vmware-tanzu/vm-operator/external/storage-policy-quota/api/v1alpha1"
spqv1 "github.com/vmware-tanzu/vm-operator/external/storage-policy-quota/api/v1alpha2"
pkgcfg "github.com/vmware-tanzu/vm-operator/pkg/config"
pkgctx "github.com/vmware-tanzu/vm-operator/pkg/context"
"github.com/vmware-tanzu/vm-operator/pkg/record"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client"

vmopv1 "github.com/vmware-tanzu/vm-operator/api/v1alpha3"
spqv1 "github.com/vmware-tanzu/vm-operator/external/storage-policy-quota/api/v1alpha1"
spqv1 "github.com/vmware-tanzu/vm-operator/external/storage-policy-quota/api/v1alpha2"
"github.com/vmware-tanzu/vm-operator/pkg/constants/testlabels"
spqutil "github.com/vmware-tanzu/vm-operator/pkg/util/kube/spq"
"github.com/vmware-tanzu/vm-operator/pkg/util/ptr"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (

vmopv1 "github.com/vmware-tanzu/vm-operator/api/v1alpha3"
"github.com/vmware-tanzu/vm-operator/controllers/storagepolicyquota"
spqv1 "github.com/vmware-tanzu/vm-operator/external/storage-policy-quota/api/v1alpha1"
spqv1 "github.com/vmware-tanzu/vm-operator/external/storage-policy-quota/api/v1alpha2"
pkgcfg "github.com/vmware-tanzu/vm-operator/pkg/config"
"github.com/vmware-tanzu/vm-operator/pkg/constants/testlabels"
spqutil "github.com/vmware-tanzu/vm-operator/pkg/util/kube/spq"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/source"

vmopv1 "github.com/vmware-tanzu/vm-operator/api/v1alpha3"
spqv1 "github.com/vmware-tanzu/vm-operator/external/storage-policy-quota/api/v1alpha1"
spqv1 "github.com/vmware-tanzu/vm-operator/external/storage-policy-quota/api/v1alpha2"
"github.com/vmware-tanzu/vm-operator/pkg/conditions"
pkgcfg "github.com/vmware-tanzu/vm-operator/pkg/config"
pkgctx "github.com/vmware-tanzu/vm-operator/pkg/context"
Expand Down Expand Up @@ -169,12 +169,7 @@ func (r *Reconciler) ReconcileNormal(
obj.Status.ResourceTypeLevelQuotaUsage.Reserved = &totalReserved
obj.Status.ResourceTypeLevelQuotaUsage.Used = &totalUsed

//
// Please note, the v1a1 StoragePolicyUsage object does not use a status
// sub-resource for some reason, thus the normal client is used to patch
// the object.
//
if err := r.Client.Patch(ctx, &obj, objPatch); err != nil {
if err := r.Client.Status().Patch(ctx, &obj, objPatch); err != nil {
return fmt.Errorf(
"failed to patch StoragePolicyUsage %s: %w", objKey, err)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client"

vmopv1 "github.com/vmware-tanzu/vm-operator/api/v1alpha3"
spqv1 "github.com/vmware-tanzu/vm-operator/external/storage-policy-quota/api/v1alpha1"
spqv1 "github.com/vmware-tanzu/vm-operator/external/storage-policy-quota/api/v1alpha2"
"github.com/vmware-tanzu/vm-operator/pkg/constants/testlabels"
"github.com/vmware-tanzu/vm-operator/pkg/util/kube/cource"
spqutil "github.com/vmware-tanzu/vm-operator/pkg/util/kube/spq"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (

vmopv1 "github.com/vmware-tanzu/vm-operator/api/v1alpha3"
"github.com/vmware-tanzu/vm-operator/controllers/virtualmachine/storagepolicyusage"
spqv1 "github.com/vmware-tanzu/vm-operator/external/storage-policy-quota/api/v1alpha1"
spqv1 "github.com/vmware-tanzu/vm-operator/external/storage-policy-quota/api/v1alpha2"
pkgcfg "github.com/vmware-tanzu/vm-operator/pkg/config"
"github.com/vmware-tanzu/vm-operator/pkg/constants/testlabels"
spqutil "github.com/vmware-tanzu/vm-operator/pkg/util/kube/spq"
Expand Down Expand Up @@ -386,18 +386,19 @@ func unitTestsReconcile() {
})
When("there is an error patching the StoragePolicyUsage resource", func() {
BeforeEach(func() {
withFuncs.Patch = func(
withFuncs.SubResourcePatch = func(
ctx context.Context,
client ctrlclient.WithWatch,
client ctrlclient.Client,
subResourceName string,
obj ctrlclient.Object,
patch ctrlclient.Patch,
opts ...ctrlclient.PatchOption) error {
opts ...ctrlclient.SubResourcePatchOption) error {

if _, ok := obj.(*spqv1.StoragePolicyUsage); ok {
return fmt.Errorf(fake)
}

return client.Patch(ctx, obj, patch, opts...)
return client.Status().Patch(ctx, obj, patch, opts...)
}
})
It("should return an error", func() {
Expand Down
32 changes: 32 additions & 0 deletions external/storage-policy-quota/api/v1alpha2/groupversion_info.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Copyright (c) 2024 VMware, Inc. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

// Package v1alpha2 contains API Schema definitions for the cns v1alpha2 API group
// +kubebuilder:object:generate=true
// +groupName=cns.vmware.com
package v1alpha2

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
)

var (
// GroupVersion is group version used to register these objects
GroupVersion = schema.GroupVersion{Group: "cns.vmware.com", Version: "v1alpha2"}

// schemeBuilder is used to add go types to the GroupVersionKind scheme.
schemeBuilder = runtime.NewSchemeBuilder(addKnownTypes)

// AddToScheme adds the types in this group-version to the given scheme.
AddToScheme = schemeBuilder.AddToScheme

objectTypes = []runtime.Object{}
)

func addKnownTypes(scheme *runtime.Scheme) error {
scheme.AddKnownTypes(GroupVersion, objectTypes...)
metav1.AddToGroupVersion(scheme, GroupVersion)
return nil
}
Loading

0 comments on commit 84365f4

Please sign in to comment.