Skip to content

Commit

Permalink
feat(kuma-cp) validate resources on kubernetes
Browse files Browse the repository at this point in the history
  • Loading branch information
jakubdyszkiewicz authored Nov 12, 2019
1 parent 12485cd commit b6ddb84
Show file tree
Hide file tree
Showing 16 changed files with 472 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3234,3 +3234,32 @@ webhooks:
- CREATE
resources:
- pods
---
apiVersion: admissionregistration.k8s.io/v1beta1
kind: ValidatingWebhookConfiguration
metadata:
name: kuma-validating-webhook-configuration
webhooks:
- name: validator.kuma-admission.kuma.io
failurePolicy: Fail
clientConfig:
caBundle: Q0VSVA==
service:
namespace: kuma-system
name: kuma-control-plane
path: /validate-kuma-io-v1alpha1
rules:
- apiGroups:
- kuma.io
apiVersions:
- v1alpha1
operations:
- CREATE
- UPDATE
resources:
- trafficlogs
- trafficpermissions
- trafficroutes
- dataplanes
- meshes
- proxytemplates
Original file line number Diff line number Diff line change
Expand Up @@ -3235,3 +3235,32 @@ webhooks:
- CREATE
resources:
- pods
---
apiVersion: admissionregistration.k8s.io/v1beta1
kind: ValidatingWebhookConfiguration
metadata:
name: kuma-validating-webhook-configuration
webhooks:
- name: validator.kuma-admission.kuma.io
failurePolicy: Fail
clientConfig:
caBundle: QWRtaXNzaW9uQ2VydA==
service:
namespace: kuma
name: kuma-ctrl-plane
path: /validate-kuma-io-v1alpha1
rules:
- apiGroups:
- kuma.io
apiVersions:
- v1alpha1
operations:
- CREATE
- UPDATE
resources:
- trafficlogs
- trafficpermissions
- trafficroutes
- dataplanes
- meshes
- proxytemplates
29 changes: 29 additions & 0 deletions app/kumactl/data/install/k8s/control-plane/kuma-cp/app.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -182,3 +182,32 @@ webhooks:
- UPDATE
resources:
- meshes
---
apiVersion: admissionregistration.k8s.io/v1beta1
kind: ValidatingWebhookConfiguration
metadata:
name: kuma-validating-webhook-configuration
webhooks:
- name: validator.kuma-admission.kuma.io
failurePolicy: Fail
clientConfig:
caBundle: {{ .AdmissionServerTlsCert | b64enc }}
service:
namespace: {{ .Namespace }}
name: {{ .ControlPlaneServiceName }}
path: /validate-kuma-io-v1alpha1
rules:
- apiGroups:
- kuma.io
apiVersions:
- v1alpha1
operations:
- CREATE
- UPDATE
resources:
- trafficlogs
- trafficpermissions
- trafficroutes
- dataplanes
- meshes
- proxytemplates
14 changes: 7 additions & 7 deletions app/kumactl/pkg/install/k8s/control-plane/templates_vfsdata.go

Large diffs are not rendered by default.

38 changes: 38 additions & 0 deletions pkg/plugins/resources/k8s/consistent_kind_type_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package k8s

import (
core_registry "github.com/Kong/kuma/pkg/core/resources/registry"
k8s_registry "github.com/Kong/kuma/pkg/plugins/resources/k8s/native/pkg/registry"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)

var _ = Describe("Consistent Kind Types", func() {
It("Kind for objects is the same as ResourceType", func() {
types := core_registry.Global()
k8sTypes := k8s_registry.Global()

for _, typ := range types.ObjectTypes() {
res, err := types.NewObject(typ)
Expect(err).ToNot(HaveOccurred())
obj, err := k8sTypes.NewObject(res.GetSpec())
Expect(err).ToNot(HaveOccurred())

Expect(obj.GetObjectKind().GroupVersionKind().Kind).To(Equal(string(res.GetType())))
}
})

It("Kind for lists is the same as ResourceType", func() {
types := core_registry.Global()
k8sTypes := k8s_registry.Global()

for _, typ := range types.ListTypes() {
res, err := types.NewObject(typ)
Expect(err).ToNot(HaveOccurred())
obj, err := k8sTypes.NewObject(res.GetSpec())
Expect(err).ToNot(HaveOccurred())

Expect(obj.GetObjectKind().GroupVersionKind().Kind).To(Equal(string(res.GetType())))
}
})
})
19 changes: 19 additions & 0 deletions pkg/plugins/resources/k8s/k8s_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ limitations under the License.
package k8s_test

import (
"github.com/Kong/kuma/pkg/test/apis/sample/v1alpha1"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"path/filepath"
"testing"

Expand All @@ -29,6 +31,8 @@ import (
logf "sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/log/zap"

k8s_registry "github.com/Kong/kuma/pkg/plugins/resources/k8s/native/pkg/registry"

// +kubebuilder:scaffold:imports
sample_v1alpha1 "github.com/Kong/kuma/pkg/plugins/resources/k8s/native/test/api/sample/v1alpha1"
)
Expand Down Expand Up @@ -66,6 +70,21 @@ var _ = BeforeSuite(func(done Done) {
Expect(err).ToNot(HaveOccurred())
Expect(k8sClient).ToNot(BeNil())

err = k8s_registry.Global().RegisterObjectType(&v1alpha1.TrafficRoute{}, &sample_v1alpha1.SampleTrafficRoute{
TypeMeta: v1.TypeMeta{
APIVersion: sample_v1alpha1.GroupVersion.String(),
Kind: "SampleTrafficRoute",
},
})
Expect(err).ToNot(HaveOccurred())
err = k8s_registry.Global().RegisterListType(&v1alpha1.TrafficRoute{}, &sample_v1alpha1.SampleTrafficRouteList{
TypeMeta: v1.TypeMeta{
APIVersion: sample_v1alpha1.GroupVersion.String(),
Kind: "SampleTrafficRouteList",
},
})
Expect(err).ToNot(HaveOccurred())

close(done)
}, 60)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,25 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// TrafficRouteSpec defines the desired state of TrafficRoute
// TrafficRouteSpec defines the desired state of SampleTrafficRoute
type TrafficRouteSpec = map[string]interface{}

// TrafficRoute is the Schema for the proxytemplates API
type TrafficRoute struct {
// SampleTrafficRoute is the Schema for the proxytemplates API
type SampleTrafficRoute struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Mesh string `json:"mesh"`

Spec TrafficRouteSpec `json:"spec,omitempty"`
}

// TrafficRouteList contains a list of TrafficRoute
type TrafficRouteList struct {
// SampleTrafficRouteList contains a list of SampleTrafficRoute
type SampleTrafficRouteList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []TrafficRoute `json:"items"`
Items []SampleTrafficRoute `json:"items"`
}

func init() {
SchemeBuilder.Register(&TrafficRoute{}, &TrafficRouteList{})
SchemeBuilder.Register(&SampleTrafficRoute{}, &SampleTrafficRouteList{})
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,57 +5,57 @@ import (
)

// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *TrafficRoute) DeepCopyInto(out *TrafficRoute) {
func (in *SampleTrafficRoute) DeepCopyInto(out *SampleTrafficRoute) {
*out = *in
out.TypeMeta = in.TypeMeta
in.ObjectMeta.DeepCopyInto(&out.ObjectMeta)
out.Spec = runtime.DeepCopyJSON(in.Spec)
}

// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new TrafficRoute.
func (in *TrafficRoute) DeepCopy() *TrafficRoute {
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new SampleTrafficRoute.
func (in *SampleTrafficRoute) DeepCopy() *SampleTrafficRoute {
if in == nil {
return nil
}
out := new(TrafficRoute)
out := new(SampleTrafficRoute)
in.DeepCopyInto(out)
return out
}

// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object.
func (in *TrafficRoute) DeepCopyObject() runtime.Object {
func (in *SampleTrafficRoute) DeepCopyObject() runtime.Object {
if c := in.DeepCopy(); c != nil {
return c
}
return nil
}

// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *TrafficRouteList) DeepCopyInto(out *TrafficRouteList) {
func (in *SampleTrafficRouteList) DeepCopyInto(out *SampleTrafficRouteList) {
*out = *in
out.TypeMeta = in.TypeMeta
out.ListMeta = in.ListMeta
if in.Items != nil {
in, out := &in.Items, &out.Items
*out = make([]TrafficRoute, len(*in))
*out = make([]SampleTrafficRoute, len(*in))
for i := range *in {
(*in)[i].DeepCopyInto(&(*out)[i])
}
}
}

// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new TrafficRouteList.
func (in *TrafficRouteList) DeepCopy() *TrafficRouteList {
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new SampleTrafficRouteList.
func (in *SampleTrafficRouteList) DeepCopy() *SampleTrafficRouteList {
if in == nil {
return nil
}
out := new(TrafficRouteList)
out := new(SampleTrafficRouteList)
in.DeepCopyInto(out)
return out
}

// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object.
func (in *TrafficRouteList) DeepCopyObject() runtime.Object {
func (in *SampleTrafficRouteList) DeepCopyObject() runtime.Object {
if c := in.DeepCopy(); c != nil {
return c
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,31 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

func (pt *TrafficRoute) GetObjectMeta() *metav1.ObjectMeta {
func (pt *SampleTrafficRoute) GetObjectMeta() *metav1.ObjectMeta {
return &pt.ObjectMeta
}

func (pt *TrafficRoute) SetObjectMeta(m *metav1.ObjectMeta) {
func (pt *SampleTrafficRoute) SetObjectMeta(m *metav1.ObjectMeta) {
pt.ObjectMeta = *m
}

func (pt *TrafficRoute) GetMesh() string {
func (pt *SampleTrafficRoute) GetMesh() string {
return pt.Mesh
}

func (pt *TrafficRoute) SetMesh(mesh string) {
func (pt *SampleTrafficRoute) SetMesh(mesh string) {
pt.Mesh = mesh
}

func (pt *TrafficRoute) GetSpec() map[string]interface{} {
func (pt *SampleTrafficRoute) GetSpec() map[string]interface{} {
return pt.Spec
}

func (pt *TrafficRoute) SetSpec(spec map[string]interface{}) {
func (pt *SampleTrafficRoute) SetSpec(spec map[string]interface{}) {
pt.Spec = spec
}

func (l *TrafficRouteList) GetItems() []model.KubernetesObject {
func (l *SampleTrafficRouteList) GetItems() []model.KubernetesObject {
result := make([]model.KubernetesObject, len(l.Items))
for i := range l.Items {
result[i] = &l.Items[i]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ metadata:
spec:
group: sample.test.kuma.io
names:
kind: TrafficRoute
kind: SampleTrafficRoute
plural: trafficroutes
scope: ""
versions:
Expand Down
4 changes: 2 additions & 2 deletions pkg/plugins/resources/k8s/store_template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ var _ = Describe("KubernetesStore template", func() {

test_store.ExecuteStoreTests(func() store.ResourceStore {
kubeTypes := k8s_registry.NewTypeRegistry()
Expect(kubeTypes.RegisterObjectType(&sample_proto.TrafficRoute{}, &sample_k8s.TrafficRoute{})).To(Succeed())
Expect(kubeTypes.RegisterListType(&sample_proto.TrafficRoute{}, &sample_k8s.TrafficRouteList{})).To(Succeed())
Expect(kubeTypes.RegisterObjectType(&sample_proto.TrafficRoute{}, &sample_k8s.SampleTrafficRoute{})).To(Succeed())
Expect(kubeTypes.RegisterListType(&sample_proto.TrafficRoute{}, &sample_k8s.SampleTrafficRouteList{})).To(Succeed())

ks := &k8s.KubernetesStore{
Client: k8sClient,
Expand Down
Loading

0 comments on commit b6ddb84

Please sign in to comment.