Skip to content
This repository has been archived by the owner on Mar 6, 2024. It is now read-only.

Commit

Permalink
Deprecate KindOverride fields and use internal api group. (#531)
Browse files Browse the repository at this point in the history
* Remove the KindOverride

* Fix api group with internal/external prefix

* Update

* Update

* Remove external prefix
  • Loading branch information
jiachengxu committed Jul 31, 2020
1 parent 7523a58 commit 39a3142
Show file tree
Hide file tree
Showing 31 changed files with 40 additions and 138 deletions.
Expand Up @@ -44,11 +44,11 @@ spec:
\ \n **Example with limited fields** ```yaml apiVersion: catalog.kubecarrier.io/v1alpha1\
\ kind: CatalogEntry metadata: name: couchdbs.eu-west-1 spec: metadata:\
\ displayName: CouchDB description: The compfy database baseCRD:\
\ name: couchdbs.eu-west-1.loodse derive: kindOverride: CouchDBPublic\
\ expose: - versions: - v1alpha1 fields: - jsonPath:\
\ .spec.username - jsonPath: .spec.password - jsonPath: .status.phase\
\ - jsonPath: .status.fauxtonAddress - jsonPath: .status.address\
\ - jsonPath: .status.observedGeneration ```"
\ name: couchdbs.eu-west-1.loodse derive: expose: - versions:\
\ - v1alpha1 fields: - jsonPath: .spec.username \
\ - jsonPath: .spec.password - jsonPath: .status.phase -\
\ jsonPath: .status.fauxtonAddress - jsonPath: .status.address \
\ - jsonPath: .status.observedGeneration ```"
properties:
apiVersion:
description: 'APIVersion defines the versioned schema of this representation
Expand Down Expand Up @@ -115,9 +115,6 @@ spec:
- versions
type: object
type: array
kindOverride:
description: overrides the kind of the derived CRD.
type: string
required:
- expose
type: object
Expand Down
Expand Up @@ -96,9 +96,6 @@ spec:
- versions
type: object
type: array
kindOverride:
description: overrides the kind of the derived CRD.
type: string
required:
- expose
type: object
Expand All @@ -115,9 +112,6 @@ spec:
required:
- name
type: object
kindOverride:
description: KindOverride overrides resulting internal CRDs kind
type: string
serviceClusterSelector:
description: ServiceClusterSelector references a set of ServiceClusters
to search the CustomResourceDefinition on.
Expand Down
Expand Up @@ -97,9 +97,6 @@ spec:
type: object
minItems: 1
type: array
kindOverride:
description: overrides the kind of the derived CRD.
type: string
required:
- baseCRD
- expose
Expand Down
Expand Up @@ -72,9 +72,6 @@ spec:
required:
- name
type: object
kindOverride:
description: KindOverride overrides the kind of the discovered CRD.
type: string
serviceCluster:
description: ServiceCluster references a ServiceCluster to search
the CustomResourceDefinition on.
Expand Down
Expand Up @@ -63,9 +63,6 @@ spec:
required:
- name
type: object
kindOverride:
description: KindOverride overrides the kind of the discovered CRD.
type: string
serviceClusterSelector:
description: ServiceClusterSelector references a set of ServiceClusters
to search the CustomResourceDefinition on.
Expand Down
6 changes: 0 additions & 6 deletions docs/api_reference/_index.md
Expand Up @@ -102,7 +102,6 @@ CustomResourceDiscoverySpec describes the desired state of a CustomResourceDisco
| ----- | ----------- | ------ | -------- |
| crd | CRD references a CustomResourceDefinition within the ServiceCluster. | [ObjectReference.kubecarrier.io/v1alpha1](#objectreferencekubecarrieriov1alpha1) | true |
| serviceCluster | ServiceCluster references a ServiceCluster to search the CustomResourceDefinition on. | [ObjectReference.kubecarrier.io/v1alpha1](#objectreferencekubecarrieriov1alpha1) | true |
| kindOverride | KindOverride overrides the kind of the discovered CRD. | string | false |
| webhookStrategy | WebhookStrategy configs the webhook of the CRD which is registered in the management cluster by this CustomResourceDiscovery. There are two possible values for this configuration {None (by default), ServiceCluster} None (by default): Webhook will only check if there is an available ServiceClusterAssignment in the current Namespace. ServiceCluster: Webhook will call webhooks of the CRD in the ServiceCluster with dry-run flag. | WebhookStrategyType.kubecarrier.io/v1alpha1 | false |

[Back to Group](#core)
Expand Down Expand Up @@ -189,7 +188,6 @@ CustomResourceDiscoverySetSpec describes the desired state of a CustomResourceDi
| ----- | ----------- | ------ | -------- |
| crd | CRD references a CustomResourceDefinition within the ServiceCluster. | [ObjectReference.kubecarrier.io/v1alpha1](#objectreferencekubecarrieriov1alpha1) | true |
| serviceClusterSelector | ServiceClusterSelector references a set of ServiceClusters to search the CustomResourceDefinition on. | [metav1.LabelSelector](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.14/#labelselector-v1-meta) | true |
| kindOverride | KindOverride overrides the kind of the discovered CRD. | string | false |
| webhookStrategy | WebhookStrategy configs the webhooks of the CRDs which are registered in the management cluster by this CustomResourceDiscoverySet. There are two possible values for this configuration {None (by default), ServiceCluster} None (by default): Webhook will only check if there is an available ServiceClusterAssignment in the current Namespace. ServiceCluster: Webhook will call webhooks of the CRD in the ServiceCluster with dry-run flag. | WebhookStrategyType.kubecarrier.io/v1alpha1 | false |

[Back to Group](#core)
Expand Down Expand Up @@ -629,7 +627,6 @@ spec:
baseCRD:
name: couchdbs.eu-west-1.loodse
derive:
kindOverride: CouchDBPublic
expose:
- versions:
- v1alpha1
Expand Down Expand Up @@ -716,7 +713,6 @@ DerivedConfig can be used to limit fields that should be exposed to a Tenant.

| Field | Description | Scheme | Required |
| ----- | ----------- | ------ | -------- |
| kindOverride | overrides the kind of the derived CRD. | string | false |
| expose | controls which fields will be present in the derived CRD. | [][VersionExposeConfig.catalog.kubecarrier.io/v1alpha1](#versionexposeconfigcatalogkubecarrieriov1alpha1) | true |

[Back to Group](#catalog)
Expand Down Expand Up @@ -816,7 +812,6 @@ CatalogEntrySetStatus defines the observed state of CatalogEntrySet.
| ----- | ----------- | ------ | -------- |
| crd | CRD references a CustomResourceDefinition within the ServiceCluster. | [ObjectReference.catalog.kubecarrier.io/v1alpha1](#objectreferencecatalogkubecarrieriov1alpha1) | true |
| serviceClusterSelector | ServiceClusterSelector references a set of ServiceClusters to search the CustomResourceDefinition on. | [metav1.LabelSelector](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.14/#labelselector-v1-meta) | true |
| kindOverride | KindOverride overrides resulting internal CRDs kind | string | false |
| webhookStrategy | WebhookStrategy configs the webhook of the CRD which is registered in the management cluster by CustomResourceDiscovery object. There are two possible values for this configuration {None (by default), ServiceCluster} None (by default): Webhook will only check if there is an available ServiceClusterAssignment in the current Namespace. ServiceCluster: Webhook will call webhooks of the CRD in the ServiceCluster with dry-run flag. | corev1alpha1.WebhookStrategyType | false |

[Back to Group](#catalog)
Expand Down Expand Up @@ -892,7 +887,6 @@ DerivedCustomResourceSpec defines the desired state of DerivedCustomResource.
| Field | Description | Scheme | Required |
| ----- | ----------- | ------ | -------- |
| baseCRD | CRD that should be used as a base to derive a new CRD from. | [ObjectReference.catalog.kubecarrier.io/v1alpha1](#objectreferencecatalogkubecarrieriov1alpha1) | true |
| kindOverride | overrides the kind of the derived CRD. | string | false |
| expose | controls which fields will be present in the derived CRD. | [][VersionExposeConfig.catalog.kubecarrier.io/v1alpha1](#versionexposeconfigcatalogkubecarrieriov1alpha1) | true |

[Back to Group](#catalog)
Expand Down
2 changes: 0 additions & 2 deletions docs/manifests/catalogentryset.yaml
Expand Up @@ -18,9 +18,7 @@ spec:
crd:
name: couchdbs.couchdb.io
serviceClusterSelector: {}
kindOverride: CouchDBInternal
derive:
kindOverride: CouchDB
expose:
- versions:
- v1alpha1
Expand Down
3 changes: 0 additions & 3 deletions pkg/apis/catalog/v1alpha1/catalogentry_types.go
Expand Up @@ -32,8 +32,6 @@ type CatalogEntrySpec struct {

// DerivedConfig can be used to limit fields that should be exposed to a Tenant.
type DerivedConfig struct {
// overrides the kind of the derived CRD.
KindOverride string `json:"kindOverride,omitempty"`
// controls which fields will be present in the derived CRD.
Expose []VersionExposeConfig `json:"expose"`
}
Expand Down Expand Up @@ -200,7 +198,6 @@ func (s *CatalogEntryStatus) SetCondition(condition CatalogEntryCondition) {
// baseCRD:
// name: couchdbs.eu-west-1.loodse
// derive:
// kindOverride: CouchDBPublic
// expose:
// - versions:
// - v1alpha1
Expand Down
2 changes: 0 additions & 2 deletions pkg/apis/catalog/v1alpha1/catalogentryset_types.go
Expand Up @@ -37,8 +37,6 @@ type CustomResourceDiscoverySetConfig struct {
CRD ObjectReference `json:"crd"`
// ServiceClusterSelector references a set of ServiceClusters to search the CustomResourceDefinition on.
ServiceClusterSelector metav1.LabelSelector `json:"serviceClusterSelector"`
// KindOverride overrides resulting internal CRDs kind
KindOverride string `json:"kindOverride,omitempty"`
// WebhookStrategy configs the webhook of the CRD which is registered in the management cluster by CustomResourceDiscovery object.
// There are two possible values for this configuration {None (by default), ServiceCluster}
// None (by default): Webhook will only check if there is an available ServiceClusterAssignment in the current Namespace.
Expand Down
2 changes: 0 additions & 2 deletions pkg/apis/catalog/v1alpha1/derivedcustomresource_types.go
Expand Up @@ -22,8 +22,6 @@ import metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
type DerivedCustomResourceSpec struct {
// CRD that should be used as a base to derive a new CRD from.
BaseCRD ObjectReference `json:"baseCRD"`
// overrides the kind of the derived CRD.
KindOverride string `json:"kindOverride,omitempty"`
// controls which fields will be present in the derived CRD.
// +kubebuilder:validation:MinItems=1
Expose []VersionExposeConfig `json:"expose"`
Expand Down
2 changes: 0 additions & 2 deletions pkg/apis/core/v1alpha1/customresourcediscovery_types.go
Expand Up @@ -27,8 +27,6 @@ type CustomResourceDiscoverySpec struct {
CRD ObjectReference `json:"crd"`
// ServiceCluster references a ServiceCluster to search the CustomResourceDefinition on.
ServiceCluster ObjectReference `json:"serviceCluster"`
// KindOverride overrides the kind of the discovered CRD.
KindOverride string `json:"kindOverride,omitempty"`
// WebhookStrategy configs the webhook of the CRD which is registered in the management cluster by this CustomResourceDiscovery.
// There are two possible values for this configuration {None (by default), ServiceCluster}
// None (by default): Webhook will only check if there is an available ServiceClusterAssignment in the current Namespace.
Expand Down
2 changes: 0 additions & 2 deletions pkg/apis/core/v1alpha1/customresourcediscoveryset_types.go
Expand Up @@ -26,8 +26,6 @@ type CustomResourceDiscoverySetSpec struct {
CRD ObjectReference `json:"crd"`
// ServiceClusterSelector references a set of ServiceClusters to search the CustomResourceDefinition on.
ServiceClusterSelector metav1.LabelSelector `json:"serviceClusterSelector"`
// KindOverride overrides the kind of the discovered CRD.
KindOverride string `json:"kindOverride,omitempty"`
// WebhookStrategy configs the webhooks of the CRDs which are registered in the management cluster by this CustomResourceDiscoverySet.
// There are two possible values for this configuration {None (by default), ServiceCluster}
// None (by default): Webhook will only check if there is an available ServiceClusterAssignment in the current Namespace.
Expand Down
2 changes: 2 additions & 0 deletions pkg/internal/constants/kubecarrier.go
Expand Up @@ -20,4 +20,6 @@ const (
KubeCarrierDefaultName = "kubecarrier"

KubeCarrierDefaultNamespace = "kubecarrier-system"

InternalAPIGroupPrefix = "internal"
)
29 changes: 5 additions & 24 deletions pkg/internal/resources/manager/manager.golden.yaml
Expand Up @@ -294,11 +294,11 @@
with limited fields** ```yaml apiVersion: catalog.kubecarrier.io/v1alpha1
kind: CatalogEntry metadata: name: couchdbs.eu-west-1 spec: metadata:
\ displayName: CouchDB description: The compfy database baseCRD:
\ name: couchdbs.eu-west-1.loodse derive: kindOverride: CouchDBPublic
\ expose: - versions: - v1alpha1 fields: - jsonPath:
.spec.username - jsonPath: .spec.password - jsonPath: .status.phase
\ - jsonPath: .status.fauxtonAddress - jsonPath: .status.address
\ - jsonPath: .status.observedGeneration ```"
\ name: couchdbs.eu-west-1.loodse derive: expose: - versions:
\ - v1alpha1 fields: - jsonPath: .spec.username -
jsonPath: .spec.password - jsonPath: .status.phase - jsonPath:
.status.fauxtonAddress - jsonPath: .status.address - jsonPath:
.status.observedGeneration ```"
properties:
apiVersion:
description: 'APIVersion defines the versioned schema of this representation
Expand Down Expand Up @@ -365,9 +365,6 @@
- versions
type: object
type: array
kindOverride:
description: overrides the kind of the derived CRD.
type: string
required:
- expose
type: object
Expand Down Expand Up @@ -694,9 +691,6 @@
- versions
type: object
type: array
kindOverride:
description: overrides the kind of the derived CRD.
type: string
required:
- expose
type: object
Expand All @@ -713,10 +707,6 @@
required:
- name
type: object
kindOverride:
description: KindOverride overrides resulting internal CRDs
kind
type: string
serviceClusterSelector:
description: ServiceClusterSelector references a set of ServiceClusters
to search the CustomResourceDefinition on.
Expand Down Expand Up @@ -1246,9 +1236,6 @@
type: object
minItems: 1
type: array
kindOverride:
description: overrides the kind of the derived CRD.
type: string
required:
- baseCRD
- expose
Expand Down Expand Up @@ -1883,9 +1870,6 @@
required:
- name
type: object
kindOverride:
description: KindOverride overrides the kind of the discovered CRD.
type: string
serviceCluster:
description: ServiceCluster references a ServiceCluster to search
the CustomResourceDefinition on.
Expand Down Expand Up @@ -2060,9 +2044,6 @@
required:
- name
type: object
kindOverride:
description: KindOverride overrides the kind of the discovered CRD.
type: string
serviceClusterSelector:
description: ServiceClusterSelector references a set of ServiceClusters
to search the CustomResourceDefinition on.
Expand Down
2 changes: 1 addition & 1 deletion pkg/internal/resources/manager/statik.go

Large diffs are not rendered by default.

5 changes: 2 additions & 3 deletions pkg/manager/internal/controllers/catalogentry_controller.go
Expand Up @@ -269,9 +269,8 @@ func (r *CatalogEntryReconciler) reconcileDerivedCustomResource(ctx context.Cont
Namespace: catalogEntry.Namespace,
},
Spec: catalogv1alpha1.DerivedCustomResourceSpec{
BaseCRD: catalogEntry.Spec.BaseCRD,
KindOverride: catalogEntry.Spec.Derive.KindOverride,
Expose: catalogEntry.Spec.Derive.Expose,
BaseCRD: catalogEntry.Spec.BaseCRD,
Expose: catalogEntry.Spec.Derive.Expose,
},
}

Expand Down
Expand Up @@ -109,7 +109,6 @@ func TestCatalogEntryReconciler(t *testing.T) {
Name: baseCRD.Name,
},
Derive: &catalogv1alpha1.DerivedConfig{
KindOverride: "TestResource",
Expose: []catalogv1alpha1.VersionExposeConfig{
{
Versions: []string{
Expand Down
Expand Up @@ -172,7 +172,6 @@ func (r *CatalogEntrySetReconciler) reconcileCustomResourceDiscoverySet(
Name: catalogEntrySet.Spec.Discover.CRD.Name,
},
ServiceClusterSelector: catalogEntrySet.Spec.Discover.ServiceClusterSelector,
KindOverride: catalogEntrySet.Spec.Discover.KindOverride,
WebhookStrategy: catalogEntrySet.Spec.Discover.WebhookStrategy,
},
}
Expand Down
Expand Up @@ -92,7 +92,6 @@ func TestCatalogEntrySetReconciler(t *testing.T) {
},
},
Derive: &catalogv1alpha1.DerivedConfig{
KindOverride: "CatapultTenant",
Expose: []catalogv1alpha1.VersionExposeConfig{
{
Versions: []string{
Expand All @@ -109,7 +108,6 @@ func TestCatalogEntrySetReconciler(t *testing.T) {
Name: baseCRD.Name,
},
ServiceClusterSelector: metav1.LabelSelector{},
KindOverride: "CatapultInternal",
WebhookStrategy: corev1alpha1.WebhookStrategyTypeServiceCluster,
},
},
Expand Down
Expand Up @@ -38,6 +38,7 @@ import (

corev1alpha1 "k8c.io/kubecarrier/pkg/apis/core/v1alpha1"
operatorv1alpha1 "k8c.io/kubecarrier/pkg/apis/operator/v1alpha1"
"k8c.io/kubecarrier/pkg/internal/constants"
)

const crDiscoveryControllerFinalizer string = "crdiscovery.kubecarrier.io/controller"
Expand Down Expand Up @@ -146,13 +147,9 @@ func (r *CustomResourceDiscoveryReconciler) reconcileCRD(
ctx context.Context, crDiscovery *corev1alpha1.CustomResourceDiscovery,
) (*apiextensionsv1.CustomResourceDefinition, error) {
// Build desired CRD
kind := crDiscovery.Spec.KindOverride
if kind == "" {
kind = crDiscovery.Status.CRD.Spec.Names.Kind
}
kind := crDiscovery.Status.CRD.Spec.Names.Kind
plural := flect.Pluralize(strings.ToLower(kind))
group := crDiscovery.Spec.ServiceCluster.Name + "." + crDiscovery.Namespace

group := constants.InternalAPIGroupPrefix + "." + crDiscovery.Spec.ServiceCluster.Name + "." + crDiscovery.Namespace
desiredCRD := &apiextensionsv1.CustomResourceDefinition{
ObjectMeta: metav1.ObjectMeta{
Name: plural + "." + group,
Expand Down
Expand Up @@ -37,6 +37,7 @@ import (
catalogv1alpha1 "k8c.io/kubecarrier/pkg/apis/catalog/v1alpha1"
corev1alpha1 "k8c.io/kubecarrier/pkg/apis/core/v1alpha1"
operatorv1alpha1 "k8c.io/kubecarrier/pkg/apis/operator/v1alpha1"
"k8c.io/kubecarrier/pkg/internal/constants"
)

func TestCustomResourceDiscoveryReconciler(t *testing.T) {
Expand Down Expand Up @@ -135,7 +136,7 @@ func TestCustomResourceDiscoveryReconciler(t *testing.T) {

internalCRD := &apiextensionsv1.CustomResourceDefinition{}
require.NoError(t, r.Client.Get(ctx, types.NamespacedName{
Name: strings.Join([]string{"redis", serviceClusterName, crDiscovery.Namespace}, "."),
Name: strings.Join([]string{"redis", constants.InternalAPIGroupPrefix, serviceClusterName, crDiscovery.Namespace}, "."),
}, internalCRD))
assert.Equal(t, map[string]string{
"kubecarrier.io/origin-namespace": crDiscovery.Namespace,
Expand Down
Expand Up @@ -180,7 +180,6 @@ func (r *CustomResourceDiscoverySetReconciler) reconcileCRDiscovery(
ServiceCluster: corev1alpha1.ObjectReference{
Name: serviceCluster.Name,
},
KindOverride: crDiscoverySet.Spec.KindOverride,
WebhookStrategy: crDiscoverySet.Spec.WebhookStrategy,
},
}
Expand Down
Expand Up @@ -61,7 +61,6 @@ func TestCustomResourceDiscoverySetReconciler(t *testing.T) {
CRD: corev1alpha1.ObjectReference{
Name: "couchdbs.couchdb.io",
},
KindOverride: "CouchDBInternal",
},
}
crds := &corev1alpha1.CustomResourceDiscovery{
Expand Down

0 comments on commit 39a3142

Please sign in to comment.