Skip to content

Commit

Permalink
Add EntryPoint controller
Browse files Browse the repository at this point in the history
  • Loading branch information
emil-jacero committed Jun 18, 2024
1 parent aaa4cd9 commit e460279
Show file tree
Hide file tree
Showing 14 changed files with 431 additions and 1 deletion.
9 changes: 9 additions & 0 deletions PROJECT
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,13 @@ resources:
kind: EnvoyProxyClusterConfig
path: github.com/emil-jacero/kode-operator/api/v1alpha1
version: v1alpha1
- api:
crdVersion: v1
namespaced: true
controller: true
domain: jacero.io
group: kode
kind: EntryPoint
path: github.com/emil-jacero/kode-operator/api/v1alpha1
version: v1alpha1
version: "3"
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@ package v1alpha1

import (
networkingv1 "k8s.io/api/networking/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
gatewayv1 "sigs.k8s.io/gateway-api/apis/v1"
)

// GatewaySpec defines the desired state of the ingress or gateway. It will inform the kode-operator how to publish the Kode resource.
// EntryPointSpec defines the desired state of EntryPoint
type EntryPointSpec struct {
// Type is the type of the gateway. It could be ingress-api or gateway-api.
// +kubebuilder:validation:description=Type is the type of the gateway. It could be ingress-api or gateway-api.
Expand All @@ -43,6 +44,31 @@ type EntryPointSpec struct {
URL string `json:"url"`
}

// EntryPointStatus defines the observed state of EntryPoint
type EntryPointStatus struct {
}

// +kubebuilder:object:root=true
// +kubebuilder:subresource:status

// EntryPoint is the Schema for the entrypoints API
type EntryPoint struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec EntryPointSpec `json:"spec,omitempty"`
Status EntryPointStatus `json:"status,omitempty"`
}

// +kubebuilder:object:root=true

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

type IngressSpec struct {
// IngressClassName is the name of the IngressClass cluster resource.
// +kubebuilder:validation:Description="Name of the IngressClass cluster resource."
Expand Down Expand Up @@ -70,3 +96,7 @@ type GatewaySpec struct {
// +kubebuilder:validation:Description="Contains the route configuration for the Gateway."
Routes []gatewayv1.HTTPRoute `json:"routes,omitempty"`
}

func init() {
SchemeBuilder.Register(&EntryPoint{}, &EntryPointList{})
}
74 changes: 74 additions & 0 deletions api/v1alpha1/zz_generated.deepcopy.go

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

7 changes: 7 additions & 0 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,13 @@ func main() {
setupLog.Error(err, "unable to create controller", "controller", "Kode")
os.Exit(1)
}
if err = (&controller.EntryPointReconciler{
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "EntryPoint")
os.Exit(1)
}
//+kubebuilder:scaffold:builder

if err := mgr.AddHealthzCheck("healthz", healthz.Ping); err != nil {
Expand Down
74 changes: 74 additions & 0 deletions config/crd/bases/kode.jacero.io_entrypoints.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.14.0
name: entrypoints.kode.jacero.io
spec:
group: kode.jacero.io
names:
kind: EntryPoint
listKind: EntryPointList
plural: entrypoints
singular: entrypoint
scope: Namespaced
versions:
- name: v1alpha1
schema:
openAPIV3Schema:
description: EntryPoint is the Schema for the entrypoints 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: EntryPointSpec defines the desired state of EntryPoint
properties:
apiType:
description: Type is the type of the gateway. It could be ingress-api
or gateway-api.
enum:
- ingress-api
- gateway-api
type: string
type:
description: Type is the way the Kode resource is accessed. It could
be subdomain or path.
enum:
- domain
- path
type: string
url:
description: |-
URL is the domain name to use either as a suffix in the case of Type=domain or as a prefix/domain in the case of Type=path.
When the type is domain, the controller will try to publish the Kode resource as a subdomain of the given domain (e.g <kode-resource>.kode.example.com).
When the type is path, the controller will try to publish the Kode resource as a path of the given URL (e.g kode.example.com/<kode-resource>).
type: string
required:
- apiType
- type
- url
type: object
status:
description: EntryPointStatus defines the observed state of EntryPoint
type: object
type: object
served: true
storage: true
subresources:
status: {}
2 changes: 2 additions & 0 deletions config/crd/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ resources:
- bases/kode.jacero.io_kodeclustertemplates.yaml
- bases/kode.jacero.io_envoyproxyconfigs.yaml
- bases/kode.jacero.io_envoyproxyclusterconfigs.yaml
- bases/kode.jacero.io_entrypoints.yaml
#+kubebuilder:scaffold:crdkustomizeresource

patches:
Expand All @@ -21,6 +22,7 @@ patches:
#- path: patches/cainjection_in_kodeclustertemplates.yaml
#- path: patches/cainjection_in_envoyproxyconfigs.yaml
#- path: patches/cainjection_in_envoyproxyclusterconfigs.yaml
#- path: patches/cainjection_in_entrypoints.yaml
#+kubebuilder:scaffold:crdkustomizecainjectionpatch

# [WEBHOOK] To enable webhook, uncomment the following section
Expand Down
27 changes: 27 additions & 0 deletions config/rbac/entrypoint_editor_role.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# permissions for end users to edit entrypoints.
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
labels:
app.kubernetes.io/name: kode-operator
app.kubernetes.io/managed-by: kustomize
name: entrypoint-editor-role
rules:
- apiGroups:
- kode.jacero.io
resources:
- entrypoints
verbs:
- create
- delete
- get
- list
- patch
- update
- watch
- apiGroups:
- kode.jacero.io
resources:
- entrypoints/status
verbs:
- get
23 changes: 23 additions & 0 deletions config/rbac/entrypoint_viewer_role.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# permissions for end users to view entrypoints.
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
labels:
app.kubernetes.io/name: kode-operator
app.kubernetes.io/managed-by: kustomize
name: entrypoint-viewer-role
rules:
- apiGroups:
- kode.jacero.io
resources:
- entrypoints
verbs:
- get
- list
- watch
- apiGroups:
- kode.jacero.io
resources:
- entrypoints/status
verbs:
- get
2 changes: 2 additions & 0 deletions config/rbac/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ resources:
# default, aiding admins in cluster management. Those roles are
# not used by the Project itself. You can comment the following lines
# if you do not want those helpers be installed with your Project.
- entrypoint_editor_role.yaml
- entrypoint_viewer_role.yaml
- envoyproxyclusterconfig_editor_role.yaml
- envoyproxyclusterconfig_viewer_role.yaml
- envoyproxyconfig_editor_role.yaml
Expand Down
26 changes: 26 additions & 0 deletions config/rbac/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,32 @@ rules:
- patch
- update
- watch
- apiGroups:
- kode.jacero.io
resources:
- entrypoints
verbs:
- create
- delete
- get
- list
- patch
- update
- watch
- apiGroups:
- kode.jacero.io
resources:
- entrypoints/finalizers
verbs:
- update
- apiGroups:
- kode.jacero.io
resources:
- entrypoints/status
verbs:
- get
- patch
- update
- apiGroups:
- kode.kode.jacero.io
resources:
Expand Down
9 changes: 9 additions & 0 deletions config/samples/kode_v1alpha1_entrypoint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
apiVersion: kode.jacero.io/v1alpha1
kind: EntryPoint
metadata:
labels:
app.kubernetes.io/name: kode-operator
app.kubernetes.io/managed-by: kustomize
name: entrypoint-sample
spec:
# TODO(user): Add fields here
1 change: 1 addition & 0 deletions config/samples/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ resources:
- kode_v1alpha1_envoyproxyconfig.yaml
# - kode_v1alpha1_envoyproxyclusterconfig.yaml

- kode_v1alpha1_entrypoint.yaml
#+kubebuilder:scaffold:manifestskustomizesamples
Loading

0 comments on commit e460279

Please sign in to comment.