mirror of
https://github.com/harivansh-afk/agentikube.git
synced 2026-04-20 22:02:38 +00:00
init
This commit is contained in:
commit
0595d93c49
28 changed files with 1763 additions and 0 deletions
51
internal/manifest/generate.go
Normal file
51
internal/manifest/generate.go
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
package manifest
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"text/template"
|
||||
|
||||
"github.com/rathi/agentikube/internal/config"
|
||||
)
|
||||
|
||||
// Generate renders all applicable Kubernetes manifests from the embedded
|
||||
// templates using the provided configuration. Templates are selected based
|
||||
// on the compute type and warm pool settings.
|
||||
func Generate(cfg *config.Config) ([]byte, error) {
|
||||
tmpl, err := template.ParseFS(templateFS, "templates/*.yaml.tmpl")
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("parsing templates: %w", err)
|
||||
}
|
||||
|
||||
// Always-rendered templates
|
||||
names := []string{
|
||||
"namespace.yaml.tmpl",
|
||||
"storageclass-efs.yaml.tmpl",
|
||||
"sandbox-template.yaml.tmpl",
|
||||
}
|
||||
|
||||
// Conditionally add Karpenter templates
|
||||
if cfg.Compute.Type == "karpenter" {
|
||||
names = append(names,
|
||||
"karpenter-nodepool.yaml.tmpl",
|
||||
"karpenter-ec2nodeclass.yaml.tmpl",
|
||||
)
|
||||
}
|
||||
|
||||
// Conditionally add warm pool template
|
||||
if cfg.Sandbox.WarmPool.Enabled {
|
||||
names = append(names, "warm-pool.yaml.tmpl")
|
||||
}
|
||||
|
||||
var out bytes.Buffer
|
||||
for i, name := range names {
|
||||
if i > 0 {
|
||||
out.WriteString("---\n")
|
||||
}
|
||||
if err := tmpl.ExecuteTemplate(&out, name, cfg); err != nil {
|
||||
return nil, fmt.Errorf("rendering template %s: %w", name, err)
|
||||
}
|
||||
}
|
||||
|
||||
return out.Bytes(), nil
|
||||
}
|
||||
6
internal/manifest/templates.go
Normal file
6
internal/manifest/templates.go
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
package manifest
|
||||
|
||||
import "embed"
|
||||
|
||||
//go:embed templates/*.yaml.tmpl
|
||||
var templateFS embed.FS
|
||||
14
internal/manifest/templates/karpenter-ec2nodeclass.yaml.tmpl
Normal file
14
internal/manifest/templates/karpenter-ec2nodeclass.yaml.tmpl
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
apiVersion: karpenter.k8s.aws/v1
|
||||
kind: EC2NodeClass
|
||||
metadata:
|
||||
name: sandbox-nodes
|
||||
spec:
|
||||
amiSelectorTerms:
|
||||
- alias: "al2023@latest"
|
||||
subnetSelectorTerms:
|
||||
- tags:
|
||||
karpenter.sh/discovery: "{{ .Namespace }}-cluster"
|
||||
securityGroupSelectorTerms:
|
||||
- tags:
|
||||
karpenter.sh/discovery: "{{ .Namespace }}-cluster"
|
||||
role: "KarpenterNodeRole-{{ .Namespace }}-cluster"
|
||||
33
internal/manifest/templates/karpenter-nodepool.yaml.tmpl
Normal file
33
internal/manifest/templates/karpenter-nodepool.yaml.tmpl
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
apiVersion: karpenter.sh/v1
|
||||
kind: NodePool
|
||||
metadata:
|
||||
name: sandbox-pool
|
||||
spec:
|
||||
template:
|
||||
spec:
|
||||
requirements:
|
||||
- key: node.kubernetes.io/instance-type
|
||||
operator: In
|
||||
values:
|
||||
{{- range .Compute.InstanceTypes }}
|
||||
- {{ . }}
|
||||
{{- end }}
|
||||
- key: karpenter.sh/capacity-type
|
||||
operator: In
|
||||
values:
|
||||
{{- range .Compute.CapacityTypes }}
|
||||
- {{ . }}
|
||||
{{- end }}
|
||||
- key: kubernetes.io/arch
|
||||
operator: In
|
||||
values:
|
||||
- amd64
|
||||
nodeClassRef:
|
||||
name: sandbox-nodes
|
||||
group: karpenter.k8s.aws
|
||||
kind: EC2NodeClass
|
||||
limits:
|
||||
cpu: {{ .Compute.MaxCPU }}
|
||||
memory: {{ .Compute.MaxMemory }}
|
||||
disruption:
|
||||
consolidationPolicy: {{ if .Compute.Consolidation }}WhenEmptyOrUnderutilized{{ else }}WhenEmpty{{ end }}
|
||||
4
internal/manifest/templates/namespace.yaml.tmpl
Normal file
4
internal/manifest/templates/namespace.yaml.tmpl
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
apiVersion: v1
|
||||
kind: Namespace
|
||||
metadata:
|
||||
name: {{ .Namespace }}
|
||||
66
internal/manifest/templates/sandbox-template.yaml.tmpl
Normal file
66
internal/manifest/templates/sandbox-template.yaml.tmpl
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
apiVersion: agentsandbox.dev/v1
|
||||
kind: SandboxTemplate
|
||||
metadata:
|
||||
name: sandbox-template
|
||||
namespace: {{ .Namespace }}
|
||||
spec:
|
||||
template:
|
||||
spec:
|
||||
containers:
|
||||
- name: sandbox
|
||||
image: {{ .Sandbox.Image }}
|
||||
ports:
|
||||
{{- range .Sandbox.Ports }}
|
||||
- containerPort: {{ . }}
|
||||
{{- end }}
|
||||
resources:
|
||||
requests:
|
||||
cpu: {{ .Sandbox.Resources.Requests.CPU }}
|
||||
memory: {{ .Sandbox.Resources.Requests.Memory }}
|
||||
limits:
|
||||
cpu: {{ .Sandbox.Resources.Limits.CPU }}
|
||||
memory: {{ .Sandbox.Resources.Limits.Memory }}
|
||||
securityContext:
|
||||
runAsUser: {{ .Sandbox.SecurityContext.RunAsUser }}
|
||||
runAsGroup: {{ .Sandbox.SecurityContext.RunAsGroup }}
|
||||
runAsNonRoot: {{ .Sandbox.SecurityContext.RunAsNonRoot }}
|
||||
env:
|
||||
{{- range $key, $value := .Sandbox.Env }}
|
||||
- name: {{ $key }}
|
||||
value: "{{ $value }}"
|
||||
{{- end }}
|
||||
startupProbe:
|
||||
tcpSocket:
|
||||
port: {{ .Sandbox.Probes.Port }}
|
||||
failureThreshold: {{ .Sandbox.Probes.StartupFailureThreshold }}
|
||||
periodSeconds: 10
|
||||
readinessProbe:
|
||||
tcpSocket:
|
||||
port: {{ .Sandbox.Probes.Port }}
|
||||
periodSeconds: 10
|
||||
volumeMounts:
|
||||
- name: workspace
|
||||
mountPath: {{ .Sandbox.MountPath }}
|
||||
volumeClaimTemplates:
|
||||
- metadata:
|
||||
name: workspace
|
||||
spec:
|
||||
accessModes:
|
||||
- ReadWriteMany
|
||||
storageClassName: efs-sandbox
|
||||
resources:
|
||||
requests:
|
||||
storage: "10Gi"
|
||||
networkPolicy:
|
||||
egress:
|
||||
{{- if .Sandbox.NetworkPolicy.EgressAllowAll }}
|
||||
- to:
|
||||
- ipBlock:
|
||||
cidr: 0.0.0.0/0
|
||||
{{- end }}
|
||||
ingress:
|
||||
{{- range .Sandbox.NetworkPolicy.IngressPorts }}
|
||||
- ports:
|
||||
- port: {{ . }}
|
||||
protocol: TCP
|
||||
{{- end }}
|
||||
14
internal/manifest/templates/storageclass-efs.yaml.tmpl
Normal file
14
internal/manifest/templates/storageclass-efs.yaml.tmpl
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
apiVersion: storage.k8s.io/v1
|
||||
kind: StorageClass
|
||||
metadata:
|
||||
name: efs-sandbox
|
||||
provisioner: efs.csi.aws.com
|
||||
parameters:
|
||||
provisioningMode: efs-ap
|
||||
fileSystemId: {{ .Storage.FilesystemID }}
|
||||
directoryPerms: "755"
|
||||
uid: "{{ .Storage.UID }}"
|
||||
gid: "{{ .Storage.GID }}"
|
||||
basePath: {{ .Storage.BasePath }}
|
||||
reclaimPolicy: {{ .Storage.ReclaimPolicy }}
|
||||
volumeBindingMode: Immediate
|
||||
10
internal/manifest/templates/warm-pool.yaml.tmpl
Normal file
10
internal/manifest/templates/warm-pool.yaml.tmpl
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
apiVersion: agentsandbox.dev/v1
|
||||
kind: SandboxWarmPool
|
||||
metadata:
|
||||
name: sandbox-warm-pool
|
||||
namespace: {{ .Namespace }}
|
||||
spec:
|
||||
templateRef:
|
||||
name: sandbox-template
|
||||
replicas: {{ .Sandbox.WarmPool.Size }}
|
||||
ttlMinutes: {{ .Sandbox.WarmPool.TTLMinutes }}
|
||||
Loading…
Add table
Add a link
Reference in a new issue