This repository has been archived by the owner on Jan 21, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from edgefarm/feature/implement-nats-controller
Feature/implement nats controller
- Loading branch information
Showing
15 changed files
with
722 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
PWD := ${CURDIR} | ||
NAME=yakha | ||
TAG?= dev | ||
REGISTRY=localhost:5000 | ||
|
||
setup: | ||
kubectl apply -k https://github.com/metacontroller/metacontroller/manifests/production | ||
install: | ||
cd hook/; go generate ./...; cd ..; | ||
kubectl apply -f ./crds | ||
kubectl apply -f ./controller.yaml | ||
example: | ||
kubectl apply -f ./examples/network.yaml | ||
|
||
image: | ||
docker build -t $(NAME):$(TAG) -f ./hook/Dockerfile ./hook | ||
push: image | ||
docker tag $(NAME):$(TAG) mmrxx/$(NAME):$(TAG) | ||
docker push mmrxx/$(NAME):$(TAG) | ||
clean: | ||
kubectl delete -f ./examples/network.yaml | ||
kubectl delete -f ./controller.yaml | ||
kubectl -n metacontroller delete pod/metacontroller-0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
apiVersion: metacontroller.k8s.io/v1alpha1 | ||
kind: CompositeController | ||
metadata: | ||
name: leaf-nats-controller | ||
spec: | ||
generateSelector: true | ||
parentResource: | ||
apiVersion: network.edgefarm.io/v1alpha1 | ||
resource: edgenetworks | ||
childResources: | ||
- apiVersion: v1 | ||
resource: configmaps | ||
- apiVersion: apps/v1 | ||
resource: daemonsets | ||
|
||
hooks: | ||
sync: | ||
webhook: | ||
url: http://leaf-nats-controller.metacontroller/sync | ||
--- | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
name: leaf-nats-controller | ||
namespace: metacontroller | ||
spec: | ||
replicas: 1 | ||
selector: | ||
matchLabels: | ||
app: leaf-nats-controller | ||
template: | ||
metadata: | ||
labels: | ||
app: leaf-nats-controller | ||
spec: | ||
containers: | ||
- name: controller | ||
image: mmrxx/yakha:dev | ||
imagePullPolicy: Always | ||
--- | ||
apiVersion: v1 | ||
kind: Service | ||
metadata: | ||
name: leaf-nats-controller | ||
namespace: metacontroller | ||
spec: | ||
selector: | ||
app: leaf-nats-controller | ||
ports: | ||
- port: 80 | ||
targetPort: 8080 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
--- | ||
apiVersion: apiextensions.k8s.io/v1 | ||
kind: CustomResourceDefinition | ||
metadata: | ||
annotations: | ||
controller-gen.kubebuilder.io/version: v0.11.1 | ||
creationTimestamp: null | ||
name: edgenetworks.network.edgefarm.io | ||
spec: | ||
group: network.edgefarm.io | ||
names: | ||
kind: EdgeNetwork | ||
listKind: EdgeNetworkList | ||
plural: edgenetworks | ||
shortNames: | ||
- en | ||
singular: edgenetwork | ||
scope: Namespaced | ||
versions: | ||
- additionalPrinterColumns: | ||
- jsonPath: .spec.network | ||
name: NETWORK | ||
type: string | ||
- jsonPath: .metadata.creationTimestamp | ||
name: AGE | ||
type: date | ||
- jsonPath: .spec.limits.fileStorage | ||
name: FILE LIMIT | ||
priority: 1 | ||
type: string | ||
- jsonPath: .spec.limits.inMemoryStorage | ||
name: MEMORY LIMIT | ||
priority: 1 | ||
type: string | ||
name: v1alpha1 | ||
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: | ||
limits: | ||
properties: | ||
fileStorage: | ||
default: 1G | ||
pattern: ^\d+[GMKB]?$ | ||
type: string | ||
inMemoryStorage: | ||
default: 1G | ||
pattern: ^\d+[GMKB]?$ | ||
type: string | ||
required: | ||
- fileStorage | ||
- inMemoryStorage | ||
type: object | ||
network: | ||
minLength: 3 | ||
type: string | ||
nodeSelector: | ||
additionalProperties: | ||
type: string | ||
type: object | ||
required: | ||
- limits | ||
- network | ||
- nodeSelector | ||
type: object | ||
status: | ||
properties: | ||
replicas: | ||
type: integer | ||
succeeded: | ||
type: integer | ||
type: object | ||
required: | ||
- metadata | ||
- spec | ||
type: object | ||
served: true | ||
storage: true | ||
subresources: | ||
status: {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
apiVersion: network.edgefarm.io/v1alpha1 | ||
kind: EdgeNetwork | ||
metadata: | ||
name: edge-network | ||
labels: | ||
foo: bar | ||
spec: | ||
nodeSelector: | ||
company: AwesomeCompany | ||
foo: bar | ||
network: test-network-def | ||
limits: | ||
fileStorage: 10G | ||
inMemoryStorage: 1G |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
go 1.19 | ||
|
||
use ./hook |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
FROM golang:1.19 | ||
RUN mkdir /app | ||
ADD . /app | ||
WORKDIR /app | ||
|
||
RUN go mod download | ||
|
||
RUN go build -o main . | ||
|
||
CMD ["/app/main"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
//go:build generate | ||
// +build generate | ||
|
||
// Remove existing CRDs | ||
//go:generate rm -rf ../../../../crds | ||
|
||
// Generate deepcopy methodsets and CRD manifests | ||
//go:generate go run -tags generate sigs.k8s.io/controller-tools/cmd/controller-gen paths=./... crd:crdVersions=v1 output:artifacts:config=../../../../crds | ||
|
||
package v1alpha1 | ||
|
||
import ( | ||
_ "sigs.k8s.io/controller-tools/cmd/controller-gen" //nolint:typecheck | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// Package v1alpha1 contains the v1alpha1 group Stream resources of the NATS provider. | ||
// +kubebuilder:object:generate=true | ||
// +groupName=network.edgefarm.io | ||
// +versionName=v1alpha1 | ||
package v1alpha1 | ||
|
||
// Package type metadata. | ||
// const ( | ||
// Group = "network.edgefarm.io" | ||
// Version = "v1alpha1" | ||
// ) | ||
|
||
// var ( | ||
// // SchemeGroupVersion is group version used to register these objects | ||
// SchemeGroupVersion = schema.GroupVersion{Group: Group, Version: Version} | ||
|
||
// // SchemeBuilder is used to add go types to the GroupVersionKind scheme | ||
// SchemeBuilder = &scheme.Builder{GroupVersion: SchemeGroupVersion} | ||
|
||
// AddToScheme = SchemeBuilder.AddToScheme | ||
// ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package v1alpha1 | ||
|
||
import metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
|
||
// +kubebuilder:object:root=true | ||
// +kubebuilder:subresource:status | ||
// +kubebuilder:resource:scope=Namespaced | ||
// +kubebuilder:resource:categories=foo | ||
// +kubebuilder:resource:shortName=en | ||
// | ||
// +kubebuilder:printcolumn:name="NETWORK",type="string",JSONPath=".spec.network" | ||
// +kubebuilder:printcolumn:name="AGE",type="date",JSONPath=".metadata.creationTimestamp" | ||
// +kubebuilder:printcolumn:name="FILE LIMIT",type="string",priority=1,JSONPath=".spec.limits.fileStorage" | ||
// +kubebuilder:printcolumn:name="MEMORY LIMIT",type="string",priority=1,JSONPath=".spec.limits.inMemoryStorage" | ||
type EdgeNetwork struct { | ||
metav1.TypeMeta `json:",inline"` | ||
metav1.ObjectMeta `json:"metadata"` | ||
Spec EdgeNetworkSpec `json:"spec"` | ||
Status EdgeNetworkStatus `json:"status,omitempty"` | ||
} | ||
|
||
type EdgeNetworkSpec struct { | ||
// +kubebuilder:validation:Required | ||
// +kubebuilder:validation:MinLength=3 | ||
Network string `json:"network"` | ||
// +kubebuilder:validation:Required | ||
NodeSelecter map[string]string `json:"nodeSelector"` | ||
// +kubebuilder:validation:Required | ||
Limits Limits `json:"limits"` | ||
} | ||
|
||
type EdgeNetworkStatus struct { | ||
Replicas int `json:"replicas,omitempty"` | ||
Succeeded int `json:"succeeded,omitempty"` | ||
} | ||
|
||
type Limits struct { | ||
// +kubebuilder:default="1G" | ||
// +kubebuilder:validation:Pattern=^\d+[GMKB]?$ | ||
FileStorage string `json:"fileStorage"` | ||
// +kubebuilder:default="1G" | ||
// +kubebuilder:validation:Pattern=^\d+[GMKB]?$ | ||
InMemoryStorage string `json:"inMemoryStorage"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
module leaf-nats-controller | ||
|
||
go 1.19 | ||
|
||
require ( | ||
k8s.io/api v0.26.0 | ||
k8s.io/apimachinery v0.26.0 | ||
sigs.k8s.io/controller-tools v0.11.1 | ||
) | ||
|
||
require ( | ||
github.com/fatih/color v1.13.0 // indirect | ||
github.com/go-logr/logr v1.2.3 // indirect | ||
github.com/gobuffalo/flect v0.3.0 // indirect | ||
github.com/gogo/protobuf v1.3.2 // indirect | ||
github.com/google/gofuzz v1.1.0 // indirect | ||
github.com/inconshreveable/mousetrap v1.0.1 // indirect | ||
github.com/json-iterator/go v1.1.12 // indirect | ||
github.com/mattn/go-colorable v0.1.9 // indirect | ||
github.com/mattn/go-isatty v0.0.14 // indirect | ||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect | ||
github.com/modern-go/reflect2 v1.0.2 // indirect | ||
github.com/spf13/cobra v1.6.1 // indirect | ||
github.com/spf13/pflag v1.0.5 // indirect | ||
github.com/stretchr/testify v1.8.1 // indirect | ||
golang.org/x/mod v0.7.0 // indirect | ||
golang.org/x/net v0.4.0 // indirect | ||
golang.org/x/sys v0.3.0 // indirect | ||
golang.org/x/text v0.5.0 // indirect | ||
golang.org/x/tools v0.4.0 // indirect | ||
gopkg.in/inf.v0 v0.9.1 // indirect | ||
gopkg.in/yaml.v2 v2.4.0 // indirect | ||
gopkg.in/yaml.v3 v3.0.1 // indirect | ||
k8s.io/apiextensions-apiserver v0.26.0 // indirect | ||
k8s.io/klog/v2 v2.80.1 // indirect | ||
k8s.io/utils v0.0.0-20221107191617-1a15be271d1d // indirect | ||
sigs.k8s.io/json v0.0.0-20220713155537-f223a00ba0e2 // indirect | ||
sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect | ||
sigs.k8s.io/yaml v1.3.0 // indirect | ||
) |
Oops, something went wrong.