Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions apis/core/v1alpha1/generic_resource_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,28 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client"
)

// TenantOrgID returns the org this usage is billed to, falling back to the
// deprecated namespace org id until every producer sets Tenant.
func (s GenericResourceSpec) TenantOrgID() string {
if s.Tenant != nil && s.Tenant.OrgID != "" {
return s.Tenant.OrgID
}
if s.Namespace != nil {
return s.Namespace.AceOrgID
}
return ""
}

func (s GenericResourceSpec) TenantOrgMetadata() map[string]string {
if s.Tenant != nil && s.Tenant.OrgID != "" {
return s.Tenant.Metadata
}
if s.Namespace != nil {
return s.Namespace.AceOrgMetadata
}
return nil
}

func GetGenericResourceName(item client.Object) string {
return fmt.Sprintf("%s~%s", item.GetName(), item.GetObjectKind().GroupVersionKind().GroupKind())
}
Expand Down
24 changes: 22 additions & 2 deletions apis/core/v1alpha1/generic_resource_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ type GenericResourceSpec struct {
RoleResourceRequests map[api.PodRole]ResourceList `json:"roleResourceRequests,omitempty"`

Namespace *NamespaceInfo `json:"namespace,omitempty"`
Tenant *TenantInfo `json:"tenant,omitempty"`
Pods []ComputeResource `json:"pods,omitempty"`
Storage []StorageResource `json:"storage,omitempty"`

Expand All @@ -91,12 +92,31 @@ type NamespaceInfo struct {
UID types.UID `json:"uid,omitempty"`
Name string `json:"name"`
// +optional
CreationTimestamp metav1.Time `json:"creationTimestamp,omitempty"`
AceOrgID string `json:"aceOrgID,omitempty"`
CreationTimestamp metav1.Time `json:"creationTimestamp,omitempty"`
// Deprecated: use GenericResourceSpec.Tenant. Removed after one release.
AceOrgID string `json:"aceOrgID,omitempty"`
// Deprecated: use GenericResourceSpec.Tenant. Removed after one release.
AceOrgMetadata map[string]string `json:"aceOrgMetadata,omitempty"`
EnableResourceTrial bool `json:"enableResourceTrial,omitempty"`
}

// +kubebuilder:validation:Enum=namespace;cluster
type TenantSource string

const (
TenantSourceNamespace TenantSource = "namespace"
TenantSourceCluster TenantSource = "cluster"
)

// TenantInfo identifies the org a usage event is billed to, independent of how
// that org was discovered.
type TenantInfo struct {
OrgID string `json:"orgID,omitempty"`
// +optional
Metadata map[string]string `json:"metadata,omitempty"`
Source TenantSource `json:"source,omitempty"`
}

type ComputeResource struct {
// +optional
UID types.UID `json:"uid,omitempty"`
Expand Down
56 changes: 52 additions & 4 deletions apis/core/v1alpha1/openapi_generated.go

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

28 changes: 28 additions & 0 deletions apis/core/v1alpha1/zz_generated.deepcopy.go

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

21 changes: 21 additions & 0 deletions crds/core.k8s.appscode.com_genericresources.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,14 @@ spec:
namespace:
properties:
aceOrgID:
description: 'Deprecated: use GenericResourceSpec.Tenant. Removed
after one release.'
type: string
aceOrgMetadata:
additionalProperties:
type: string
description: 'Deprecated: use GenericResourceSpec.Tenant. Removed
after one release.'
type: object
creationTimestamp:
format: date-time
Expand Down Expand Up @@ -389,6 +393,23 @@ spec:
- name
type: object
type: array
tenant:
description: |-
TenantInfo identifies the org a usage event is billed to, independent of how
that org was discovered.
properties:
metadata:
additionalProperties:
type: string
type: object
orgID:
type: string
source:
enum:
- namespace
- cluster
type: string
type: object
totalResource:
properties:
limits:
Expand Down
Loading