Skip to content

Commit

Permalink
Adding CR test
Browse files Browse the repository at this point in the history
  • Loading branch information
Jordan Olshevski committed Nov 20, 2023
1 parent 0522e9e commit beb67e0
Show file tree
Hide file tree
Showing 7 changed files with 378 additions and 18 deletions.
3 changes: 2 additions & 1 deletion internal/controllers/reconciliation/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func New(mgr *reconstitution.Manager, upstream *rest.Config) error {
})
}

func (c *Controller) Name() string { return "syncController" }
func (c *Controller) Name() string { return "reconciliationController" }

func (c *Controller) Reconcile(ctx context.Context, req *reconstitution.Request) (ctrl.Result, error) {
logger := logr.FromContextOrDiscard(ctx)
Expand Down Expand Up @@ -176,6 +176,7 @@ func (c *Controller) buildPatch(ctx context.Context, prev, resource *reconstitut

model := c.openapi.LookupResource(resource.Object.GroupVersionKind())
if model == nil {
// TODO: Remove?
// Fall back to non-strategic merge
logr.FromContextOrDiscard(ctx).Info("falling back to non-strategic merge patch because resource was not found in openapi spec")
return jsonmergepatch.CreateThreeWayJSONMergePatch(prevManifest, []byte(resource.Manifest), desiredJS)
Expand Down
18 changes: 18 additions & 0 deletions internal/controllers/reconciliation/discoverycache.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package reconciliation

import (
"sync"

"k8s.io/kubectl/pkg/util/openapi"
)

// TODO

type discoveryCache struct {
mut sync.Mutex
current openapi.Resources
}

func (d *discoveryCache) Get() openapi.Resources {
return nil
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.13.0
name: testresources.enotest.azure.io
spec:
group: enotest.azure.io
names:
kind: TestResource
listKind: TestResourceList
plural: testresources
singular: testresource
scope: Namespaced
versions:
- name: v1
schema:
openAPIV3Schema:
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:
properties:
values:
items:
properties:
int:
type: integer
type: object
type: array
type: object
status:
type: object
type: object
served: true
storage: true
subresources:
status: {}
48 changes: 48 additions & 0 deletions internal/controllers/reconciliation/fixtures/v1/types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// +kubebuilder:object:generate=true
// +groupName=enotest.azure.io
package v1

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

//go:generate controller-gen object crd rbac:roleName=resourceprovider paths=./...

var (
SchemeGroupVersion = schema.GroupVersion{Group: "enotest.azure.io", Version: "v1"}
SchemeBuilder = &scheme.Builder{GroupVersion: SchemeGroupVersion}
)

func init() {
SchemeBuilder.Register(&TestResourceList{}, &TestResource{})
}

// +kubebuilder:object:root=true
type TestResourceList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []TestResource `json:"items"`
}

// +kubebuilder:object:root=true
// +kubebuilder:subresource:status
type TestResource struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec TestResourceSpec `json:"spec,omitempty"`
Status TestResourceStatus `json:"status,omitempty"`
}

type TestResourceSpec struct {
Values []*TestValue `json:"values,omitempty"`
}

type TestValue struct {
Int int `json:"int,omitempty"`
}

type TestResourceStatus struct {
}

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

Loading

0 comments on commit beb67e0

Please sign in to comment.