mirror of
https://github.com/kairos-io/entangle.git
synced 2025-11-26 09:09:08 +00:00
Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1da47ac24f | ||
|
|
297f557a04 | ||
|
|
c3cd5f5654 |
89
README.md
89
README.md
@@ -1,81 +1,34 @@
|
||||
# entangle
|
||||
// TODO(user): Add simple overview of use/purpose
|
||||
|
||||
## Description
|
||||
// TODO(user): An in-depth paragraph about your project and overview of use
|
||||
| :exclamation: | This is experimental! |
|
||||
|-|:-|
|
||||
|
||||
## Getting Started
|
||||
You’ll need a Kubernetes cluster to run against. You can use [KIND](https://sigs.k8s.io/kind) to get a local cluster for testing, or run against a remote cluster.
|
||||
**Note:** Your controller will automatically use the current context in your kubeconfig file (i.e. whatever cluster `kubectl cluster-info` shows).
|
||||
This is the Kairos entangle Kubernetes Native Extension.
|
||||
|
||||
### Running on the cluster
|
||||
1. Install Instances of Custom Resources:
|
||||
To install, use helm:
|
||||
|
||||
```sh
|
||||
kubectl apply -f config/samples/
|
||||
```
|
||||
# Adds the kairos repo to helm
|
||||
$ helm repo add kairos https://kairos-io.github.io/helm-charts
|
||||
"kairos" has been added to your repositories
|
||||
$ helm repo update
|
||||
Hang tight while we grab the latest from your chart repositories...
|
||||
...Successfully got an update from the "kairos" chart repository
|
||||
Update Complete. ⎈Happy Helming!⎈
|
||||
|
||||
2. Build and push your image to the location specified by `IMG`:
|
||||
# Install the CRD chart
|
||||
$ helm install kairos-crd kairos/kairos-crds
|
||||
NAME: kairos-crd
|
||||
LAST DEPLOYED: Tue Sep 6 20:35:34 2022
|
||||
NAMESPACE: default
|
||||
STATUS: deployed
|
||||
REVISION: 1
|
||||
TEST SUITE: None
|
||||
|
||||
```sh
|
||||
make docker-build docker-push IMG=<some-registry>/entangle:tag
|
||||
# Installs entangle
|
||||
$ helm install kairos-entangle kairos/entangle
|
||||
```
|
||||
|
||||
3. Deploy the controller to the cluster with the image specified by `IMG`:
|
||||
|
||||
```sh
|
||||
make deploy IMG=<some-registry>/entangle:tag
|
||||
```
|
||||
|
||||
### Uninstall CRDs
|
||||
To delete the CRDs from the cluster:
|
||||
|
||||
```sh
|
||||
make uninstall
|
||||
```
|
||||
|
||||
### Undeploy controller
|
||||
UnDeploy the controller to the cluster:
|
||||
|
||||
```sh
|
||||
make undeploy
|
||||
```
|
||||
|
||||
## Contributing
|
||||
// TODO(user): Add detailed information on how you would like others to contribute to this project
|
||||
|
||||
### How it works
|
||||
This project aims to follow the Kubernetes [Operator pattern](https://kubernetes.io/docs/concepts/extend-kubernetes/operator/)
|
||||
|
||||
It uses [Controllers](https://kubernetes.io/docs/concepts/architecture/controller/)
|
||||
which provides a reconcile function responsible for synchronizing resources untile the desired state is reached on the cluster
|
||||
|
||||
### Test It Out
|
||||
1. Install the CRDs into the cluster:
|
||||
|
||||
```sh
|
||||
make install
|
||||
```
|
||||
|
||||
2. Run your controller (this will run in the foreground, so switch to a new terminal if you want to leave it running):
|
||||
|
||||
```sh
|
||||
make run
|
||||
```
|
||||
|
||||
**NOTE:** You can also run this in one step by running: `make install run`
|
||||
|
||||
### Modifying the API definitions
|
||||
If you are editing the API definitions, generate the manifests such as CRs or CRDs using:
|
||||
|
||||
```sh
|
||||
make manifests
|
||||
```
|
||||
|
||||
**NOTE:** Run `make --help` for more information on all potential `make` targets
|
||||
|
||||
More information can be found via the [Kubebuilder Documentation](https://book.kubebuilder.io/introduction.html)
|
||||
|
||||
## License
|
||||
|
||||
Copyright 2022.
|
||||
|
||||
@@ -22,7 +22,7 @@ func genOwner(ent entanglev1alpha1.Entanglement) []metav1.OwnerReference {
|
||||
}
|
||||
}
|
||||
|
||||
func (r *EntanglementReconciler) genDeployment(ent entanglev1alpha1.Entanglement) (*appsv1.Deployment, error) {
|
||||
func (r *EntanglementReconciler) genDeployment(ent entanglev1alpha1.Entanglement, logLevel string) (*appsv1.Deployment, error) {
|
||||
objMeta := metav1.ObjectMeta{
|
||||
Name: ent.Name,
|
||||
Namespace: ent.Namespace,
|
||||
@@ -96,9 +96,9 @@ func (r *EntanglementReconciler) genDeployment(ent entanglev1alpha1.Entanglement
|
||||
}
|
||||
|
||||
if ent.Spec.ServiceRef != nil {
|
||||
expose.Args = []string{cmd, "--log-level", "debug", ent.Spec.ServiceUUID, fmt.Sprintf("%s:%s", fmt.Sprintf("%s.svc.cluster.local", svc.Name), ent.Spec.Port)}
|
||||
expose.Args = []string{cmd, "--log-level", logLevel, ent.Spec.ServiceUUID, fmt.Sprintf("%s:%s", fmt.Sprintf("%s.svc.cluster.local", svc.Name), ent.Spec.Port)}
|
||||
} else {
|
||||
expose.Args = []string{cmd, "--log-level", "debug", ent.Spec.ServiceUUID, fmt.Sprintf("%s:%s", ent.Spec.Host, ent.Spec.Port)}
|
||||
expose.Args = []string{cmd, "--log-level", logLevel, ent.Spec.ServiceUUID, fmt.Sprintf("%s:%s", ent.Spec.Host, ent.Spec.Port)}
|
||||
}
|
||||
|
||||
pod := v1.PodSpec{
|
||||
|
||||
@@ -38,7 +38,7 @@ type EntanglementReconciler struct {
|
||||
clientSet *kubernetes.Clientset
|
||||
client.Client
|
||||
Scheme *runtime.Scheme
|
||||
EntangleServiceImage string
|
||||
EntangleServiceImage, LogLevel string
|
||||
}
|
||||
|
||||
//+kubebuilder:rbac:groups=entangle.kairos.io,resources=entanglements,verbs=get;list;watch;create;update;patch;delete
|
||||
@@ -70,7 +70,7 @@ func (r *EntanglementReconciler) Reconcile(ctx context.Context, req ctrl.Request
|
||||
return ctrl.Result{}, err
|
||||
}
|
||||
|
||||
desiredDeployment, err := r.genDeployment(ent)
|
||||
desiredDeployment, err := r.genDeployment(ent,r.LogLevel)
|
||||
if err != nil {
|
||||
return ctrl.Result{}, err
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ type Webhook struct {
|
||||
clientSet *kubernetes.Clientset
|
||||
Scheme *runtime.Scheme
|
||||
|
||||
SidecarImage string
|
||||
SidecarImage, LogLevel string
|
||||
}
|
||||
|
||||
//+kubebuilder:rbac:groups="",resources=secrets,verbs=get;list;watch
|
||||
@@ -52,32 +52,42 @@ func (w *Webhook) SetupWebhookWithManager(mgr manager.Manager) error {
|
||||
}
|
||||
|
||||
func (w *Webhook) Mutate(ctx context.Context, request admission.Request, object runtime.Object) admission.Response {
|
||||
|
||||
_ = log.FromContext(ctx)
|
||||
|
||||
pod := object.(*corev1.Pod)
|
||||
entanglementName, exists := pod.Labels[EntanglementNameLabel]
|
||||
|
||||
// Let user use both label and annotations
|
||||
info := pod.Labels
|
||||
|
||||
// Annotations take precedence
|
||||
for ann, v := range pod.Annotations {
|
||||
info[ann] = v
|
||||
}
|
||||
|
||||
entanglementName, exists := info[EntanglementNameLabel]
|
||||
if !exists {
|
||||
return admission.Allowed("")
|
||||
}
|
||||
|
||||
entanglementPort, exists := pod.Labels[EntanglementPortLabel]
|
||||
entanglementPort, exists := info[EntanglementPortLabel]
|
||||
if !exists {
|
||||
return admission.Allowed("")
|
||||
}
|
||||
|
||||
cmd := "service-connect"
|
||||
entanglementDirection, exists := pod.Labels[EntanglementDirectionLabel]
|
||||
entanglementDirection, exists := info[EntanglementDirectionLabel]
|
||||
if exists && entanglementDirection == "entangle" {
|
||||
cmd = "service-add"
|
||||
}
|
||||
|
||||
host := "127.0.0.1"
|
||||
entanglementHost, exists := pod.Labels[EntanglementHostLabel]
|
||||
entanglementHost, exists := info[EntanglementHostLabel]
|
||||
if exists && entanglementHost != "" {
|
||||
host = entanglementHost
|
||||
}
|
||||
|
||||
entanglementService, exists := pod.Labels[EntanglementServiceLabel]
|
||||
entanglementService, exists := info[EntanglementServiceLabel]
|
||||
if !exists {
|
||||
return admission.Allowed("")
|
||||
}
|
||||
@@ -99,7 +109,7 @@ func (w *Webhook) Mutate(ctx context.Context, request admission.Request, object
|
||||
servingContainer := corev1.Container{
|
||||
ImagePullPolicy: corev1.PullAlways,
|
||||
Command: []string{"/usr/bin/edgevpn"},
|
||||
Args: []string{cmd, entanglementService, fmt.Sprintf("%s:%s", host, entanglementPort)},
|
||||
Args: []string{cmd, entanglementService, fmt.Sprintf("%s:%s", host, entanglementPort), "--log-level", w.LogLevel},
|
||||
Env: []corev1.EnvVar{
|
||||
{
|
||||
Name: "EDGEVPNTOKEN",
|
||||
|
||||
11
main.go
11
main.go
@@ -57,8 +57,13 @@ func main() {
|
||||
var metricsAddr string
|
||||
var enableLeaderElection bool
|
||||
var probeAddr string
|
||||
var serviceImage string
|
||||
var logLevel string
|
||||
flag.StringVar(&metricsAddr, "metrics-bind-address", ":8080", "The address the metric endpoint binds to.")
|
||||
flag.StringVar(&probeAddr, "health-probe-bind-address", ":8081", "The address the probe endpoint binds to.")
|
||||
flag.StringVar(&serviceImage, "service-image", defaultImage, "The image used to create services.")
|
||||
flag.StringVar(&logLevel, "service-log-level", "debug", "The log level of the sidecar container.")
|
||||
|
||||
flag.BoolVar(&enableLeaderElection, "leader-elect", false,
|
||||
"Enable leader election for controller manager. "+
|
||||
"Enabling this will ensure there is only one active controller manager.")
|
||||
@@ -97,15 +102,17 @@ func main() {
|
||||
if err = (&controllers.EntanglementReconciler{
|
||||
Client: mgr.GetClient(),
|
||||
Scheme: mgr.GetScheme(),
|
||||
EntangleServiceImage: defaultImage,
|
||||
EntangleServiceImage: serviceImage,
|
||||
LogLevel: logLevel,
|
||||
}).SetupWithManager(mgr); err != nil {
|
||||
setupLog.Error(err, "unable to create controller", "controller", "Entanglement")
|
||||
os.Exit(1)
|
||||
}
|
||||
if err = (&webhooks.Webhook{
|
||||
Client: mgr.GetClient(),
|
||||
SidecarImage: defaultImage,
|
||||
SidecarImage: serviceImage,
|
||||
Scheme: mgr.GetScheme(),
|
||||
LogLevel: logLevel,
|
||||
}).SetupWebhookWithManager(mgr); err != nil {
|
||||
setupLog.Error(err, "unable to create webhook", "webhook", "Pod")
|
||||
os.Exit(1)
|
||||
|
||||
Reference in New Issue
Block a user