Skip to content

Commit

Permalink
Odiglet based architecture - first phase (#44)
Browse files Browse the repository at this point in the history
This PR is the first phase of using odiglet (inspired by kubelet from
Kubernetes) daemonset for making instrumentations.
More documentation and explanation will be added soon.
  • Loading branch information
edeNFed authored Dec 29, 2022
1 parent 769a2c2 commit 9c221b9
Show file tree
Hide file tree
Showing 166 changed files with 24,000 additions and 15 deletions.
14 changes: 14 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,20 @@ jobs:
push: true
tags: ghcr.io/keyval-dev/odigos/lang-detector:${{ steps.vars.outputs.tag }}
build-args: SERVICE_NAME=langDetector
- name: Build Odiglet Image
uses: docker/build-push-action@v3
with:
file: odiglet/Dockerfile
context: odiglet/
push: true
tags: ghcr.io/keyval-dev/odigos/odiglet:${{ steps.vars.outputs.tag }}
- name: Build Init Image
uses: docker/build-push-action@v3
with:
file: init/Dockerfile
context: init/
push: true
tags: ghcr.io/keyval-dev/odigos/init:${{ steps.vars.outputs.tag }}
- name: Build UI Image
uses: docker/build-push-action@v3
with:
Expand Down
22 changes: 22 additions & 0 deletions cli/cmd/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ to quickly create a Cobra application.`,
client, cmd, ns, createInstrumentor)
createKubeResourceWithLogging(ctx, "Deploying Scheduler",
client, cmd, ns, createScheduler)
createKubeResourceWithLogging(ctx, "Deploying Odiglet",
client, cmd, ns, createOdiglet)
createKubeResourceWithLogging(ctx, "Deploying UI",
client, cmd, ns, createUI)
createKubeResourceWithLogging(ctx, "Deploying Autoscaler",
Expand Down Expand Up @@ -248,6 +250,26 @@ func createAutoscaler(ctx context.Context, cmd *cobra.Command, client *kube.Clie
return err
}

func createOdiglet(ctx context.Context, cmd *cobra.Command, client *kube.Client, ns string) error {
_, err := client.CoreV1().ServiceAccounts(ns).Create(ctx, resources.NewOdigletServiceAccount(), metav1.CreateOptions{})
if err != nil {
return err
}

_, err = client.RbacV1().ClusterRoles().Create(ctx, resources.NewOdigletClusterRole(), metav1.CreateOptions{})
if err != nil {
return err
}

_, err = client.RbacV1().ClusterRoleBindings().Create(ctx, resources.NewOdigletClusterRoleBinding(ns), metav1.CreateOptions{})
if err != nil {
return err
}

_, err = client.AppsV1().DaemonSets(ns).Create(ctx, resources.NewOdigletDaemonSet(versionFlag), metav1.CreateOptions{})
return err
}

func createKubeResourceWithLogging(ctx context.Context, msg string, client *kube.Client, cmd *cobra.Command, ns string, create ResourceCreationFunc) {
l := log.Print(msg)
err := create(ctx, cmd, client, ns)
Expand Down
183 changes: 183 additions & 0 deletions cli/cmd/resources/odiglet.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
package resources

import (
"fmt"
"github.com/keyval-dev/odigos/cli/pkg/labels"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
rbacv1 "k8s.io/api/rbac/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

const (
odigletImage = "ghcr.io/keyval-dev/odigos/odiglet"
)

func NewOdigletServiceAccount() *corev1.ServiceAccount {
return &corev1.ServiceAccount{
TypeMeta: metav1.TypeMeta{
Kind: "ServiceAccount",
APIVersion: "v1",
},
ObjectMeta: metav1.ObjectMeta{
Name: "odiglet",
Labels: labels.OdigosSystem,
},
}
}

func NewOdigletClusterRole() *rbacv1.ClusterRole {
return &rbacv1.ClusterRole{
TypeMeta: metav1.TypeMeta{
Kind: "ClusterRole",
APIVersion: "rbac.authorization.k8s.io/v1",
},
ObjectMeta: metav1.ObjectMeta{
Name: "odiglet",
Labels: labels.OdigosSystem,
},
Rules: []rbacv1.PolicyRule{
{
Verbs: []string{
"create",
"delete",
"get",
"list",
"patch",
"update",
"watch",
},
APIGroups: []string{""},
Resources: []string{
"pods",
},
},
{
Verbs: []string{
"get",
"update",
"patch",
},
APIGroups: []string{""},
Resources: []string{
"pods/status",
},
},
},
}
}

func NewOdigletClusterRoleBinding(ns string) *rbacv1.ClusterRoleBinding {
return &rbacv1.ClusterRoleBinding{
TypeMeta: metav1.TypeMeta{
Kind: "ClusterRoleBinding",
APIVersion: "rbac.authorization.k8s.io/v1",
},
ObjectMeta: metav1.ObjectMeta{
Name: "odiglet",
Labels: labels.OdigosSystem,
},
Subjects: []rbacv1.Subject{
{
Kind: "ServiceAccount",
Name: "odiglet",
Namespace: ns,
},
},
RoleRef: rbacv1.RoleRef{
APIGroup: "rbac.authorization.k8s.io",
Kind: "ClusterRole",
Name: "odiglet",
},
}
}

func NewOdigletDaemonSet(version string) *appsv1.DaemonSet {
return &appsv1.DaemonSet{
TypeMeta: metav1.TypeMeta{
Kind: "DaemonSet",
APIVersion: "apps/v1",
},
ObjectMeta: metav1.ObjectMeta{
Name: "odiglet",
Labels: map[string]string{
"app": "odiglet",
labels.OdigosSystemLabelKey: labels.OdigosSystemLabelValue,
},
},
Spec: appsv1.DaemonSetSpec{
Selector: &metav1.LabelSelector{
MatchLabels: map[string]string{
"app": "odiglet",
},
},
Template: corev1.PodTemplateSpec{
ObjectMeta: metav1.ObjectMeta{
Labels: map[string]string{
"app": "odiglet",
},
},
Spec: corev1.PodSpec{
Volumes: []corev1.Volume{
{
Name: "run-dir",
VolumeSource: corev1.VolumeSource{
HostPath: &corev1.HostPathVolumeSource{
Path: "/run",
},
},
},
{
Name: "var-dir",
VolumeSource: corev1.VolumeSource{
HostPath: &corev1.HostPathVolumeSource{
Path: "/var",
},
},
},
},
Containers: []corev1.Container{
{
Name: "odiglet",
Image: fmt.Sprintf("%s:%s", odigletImage, version),
Env: []corev1.EnvVar{
{
Name: "NODE_NAME",
ValueFrom: &corev1.EnvVarSource{
FieldRef: &corev1.ObjectFieldSelector{
FieldPath: "spec.nodeName",
},
},
},
},
Resources: corev1.ResourceRequirements{},
VolumeMounts: []corev1.VolumeMount{
{
Name: "run-dir",
MountPath: "/run",
MountPropagation: ptrMountPropagationMode("Bidirectional"),
},
{
Name: "var-dir",
MountPath: "/var",
MountPropagation: ptrMountPropagationMode("Bidirectional"),
},
},
ImagePullPolicy: "IfNotPresent",
SecurityContext: &corev1.SecurityContext{
Privileged: ptrbool(true),
},
},
},
DNSPolicy: "ClusterFirstWithHostNet",
ServiceAccountName: "odiglet",
HostNetwork: true,
HostPID: true,
},
},
},
}
}
func ptrMountPropagationMode(p corev1.MountPropagationMode) *corev1.MountPropagationMode {
return &p
}
23 changes: 22 additions & 1 deletion cli/cmd/uninstall.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/*
Copyright © 2022 NAME HERE <EMAIL ADDRESS>
*/
package cmd

Expand Down Expand Up @@ -46,6 +45,8 @@ to quickly create a Cobra application.`,

createKubeResourceWithLogging(ctx, "Uninstalling Odigos Deployments",
client, cmd, ns, uninstallDeployments)
createKubeResourceWithLogging(ctx, "Uninstalling Odigos DaemonSets",
client, cmd, ns, uninstallDaemonSets)
createKubeResourceWithLogging(ctx, "Uninstalling Odigos ConfigMaps",
client, cmd, ns, uninstallConfigMaps)
createKubeResourceWithLogging(ctx, "Uninstalling Odigos CRDs",
Expand Down Expand Up @@ -79,6 +80,26 @@ func uninstallDeployments(ctx context.Context, cmd *cobra.Command, client *kube.
return nil
}

func uninstallDaemonSets(ctx context.Context, cmd *cobra.Command, client *kube.Client, ns string) error {
list, err := client.AppsV1().DaemonSets(ns).List(ctx, metav1.ListOptions{
LabelSelector: metav1.FormatLabelSelector(&metav1.LabelSelector{
MatchLabels: labels.OdigosSystem,
}),
})
if err != nil {
return err
}

for _, i := range list.Items {
err = client.AppsV1().DaemonSets(ns).Delete(ctx, i.Name, metav1.DeleteOptions{})
if err != nil {
return err
}
}

return nil
}

func uninstallConfigMaps(ctx context.Context, cmd *cobra.Command, client *kube.Client, ns string) error {
list, err := client.CoreV1().ConfigMaps(ns).List(ctx, metav1.ListOptions{
LabelSelector: metav1.FormatLabelSelector(&metav1.LabelSelector{
Expand Down
9 changes: 9 additions & 0 deletions init/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM golang:1.19 AS build
WORKDIR /app
COPY . .
RUN CGO_ENABLED=0 GOOS=linux go build -o init

FROM busybox
WORKDIR /odigos
COPY --from=build /app/init /odigos-init/init
RUN chmod -R go+r /odigos-init
3 changes: 3 additions & 0 deletions init/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module github.com/keyval-dev/odigos/init

go 1.19
Loading

0 comments on commit 9c221b9

Please sign in to comment.