Skip to content
This repository has been archived by the owner on Mar 16, 2024. It is now read-only.

Commit

Permalink
Merge pull request #2419 from ibuildthecloud/main
Browse files Browse the repository at this point in the history
Local fixes
  • Loading branch information
ibuildthecloud authored Jan 17, 2024
2 parents 4eb9cea + 1164c9e commit e0dc013
Show file tree
Hide file tree
Showing 22 changed files with 373 additions and 203 deletions.
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ RUN apk add --no-cache ca-certificates iptables ip6tables fuse3 git openssh pigz
RUN adduser -D acorn
RUN mkdir /wd && \
chown acorn /wd && \
mkdir /etc/coredns
mkdir /etc/coredns && \
mkdir /lib/modules
RUN --mount=from=binfmt,src=/usr/bin,target=/usr/src for i in aarch64 x86_64; do if [ -e /usr/src/qemu-$i ]; then cp /usr/src/qemu-$i /usr/bin; fi; done
RUN --mount=from=buildkit,src=/usr/bin,target=/usr/src for i in aarch64 x86_64; do if [ -e /usr/src/buildkit-qemu-$i ]; then cp /usr/src/buildkit-qemu-$i /usr/bin; fi; done
COPY --from=binfmt /usr/bin/binfmt /usr/local/bin
Expand All @@ -64,7 +65,6 @@ COPY /scripts/acorn-job-get-output /usr/local/bin
COPY /scripts/k3s-config.yaml /etc/rancher/k3s/config.yaml
CMD []
WORKDIR /wd
VOLUME /var/lib/buildkit
VOLUME /var/lib/rancher/k3s
STOPSIGNAL SIGTERM
ENTRYPOINT ["/usr/local/bin/acorn"]
Expand Down
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ build:
tidy:
go mod tidy

dev-reset: build
docker build -t localdev .
ACORN_IMAGE=localdev ACORN_LOCAL_PORT=6442 acorn local start --delete

dev-install:
[ -e .dev-image ] && go mod vendor ; go run main.go install --dev "$$(cat .dev-image)"; rm -rf vendor

Expand Down
2 changes: 0 additions & 2 deletions pkg/cli/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,10 @@ func NewLocal(c CommandContext) *cobra.Command {
Hidden: true,
})
cmd.AddCommand(NewLocalServer(c))
cmd.AddCommand(NewLocalCreate(c))
cmd.AddCommand(NewLocalLogs(c))
cmd.AddCommand(NewLocalRm(c))
cmd.AddCommand(NewLocalStart(c))
cmd.AddCommand(NewLocalStop(c))
cmd.AddCommand(NewLocalReset(c))
return cmd
}

Expand Down
35 changes: 0 additions & 35 deletions pkg/cli/local_create.go

This file was deleted.

34 changes: 0 additions & 34 deletions pkg/cli/local_reset.go

This file was deleted.

2 changes: 1 addition & 1 deletion pkg/cli/local_rm.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func NewLocalRm(c CommandContext) *cobra.Command {
}

type LocalRm struct {
State bool `usage:"Include associated state (acorns and acorn data)"`
State bool `usage:"Include associated state (acorns, secrets and volume data)"`
}

func (a *LocalRm) Run(cmd *cobra.Command, args []string) error {
Expand Down
20 changes: 9 additions & 11 deletions pkg/cli/local_start.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package cli

import (
"fmt"

cli "github.com/acorn-io/runtime/pkg/cli/builder"
"github.com/acorn-io/runtime/pkg/local"
"github.com/spf13/cobra"
Expand All @@ -19,22 +17,22 @@ func NewLocalStart(c CommandContext) *cobra.Command {
}

type LocalStart struct {
Reset bool `usage:"Delete existing server and all data before starting"`
Delete bool `usage:"Delete existing server before starting"`
}

func (a *LocalStart) Run(cmd *cobra.Command, args []string) error {
func (a *LocalStart) Run(cmd *cobra.Command, args []string) (err error) {
c, err := local.NewContainer(cmd.Context())
if err != nil {
return err
}

if _, err := c.Create(cmd.Context(), false); err != nil {
return err
}

if err := c.Start(cmd.Context()); err != nil {
return err
if a.Reset {
return c.Reset(cmd.Context(), true)
} else if a.Delete {
return c.Reset(cmd.Context(), false)
}

fmt.Println("started")
return nil
_, _, err = c.Upgrade(cmd.Context(), false)
return err
}
4 changes: 3 additions & 1 deletion pkg/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,9 @@ func generateKubeConfig(restConfig *rest.Config) ([]byte, error) {
},
AuthInfos: map[string]*clientcmdapi.AuthInfo{
"auth": {
Token: restConfig.BearerToken,
Token: restConfig.BearerToken,
ClientCertificateData: restConfig.TLSClientConfig.CertData,
ClientKeyData: restConfig.TLSClientConfig.KeyData,
},
},
Contexts: map[string]*clientcmdapi.Context{
Expand Down
12 changes: 12 additions & 0 deletions pkg/controller/appdefinition/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ func toRouter(appInstance *v1.AppInstance, routerName string, router v1.Router,
"daemon off;",
},
VolumeMounts: []corev1.VolumeMount{
{
Name: "confd",
MountPath: "/etc/nginx/conf.d",
},
{
Name: "conf",
ReadOnly: true,
Expand Down Expand Up @@ -121,6 +125,14 @@ func toRouter(appInstance *v1.AppInstance, routerName string, router v1.Router,
},
},
Volumes: []corev1.Volume{
{
Name: "confd",
VolumeSource: corev1.VolumeSource{
EmptyDir: &corev1.EmptyDirVolumeSource{
Medium: corev1.StorageMediumMemory,
},
},
},
{
Name: "conf",
VolumeSource: corev1.VolumeSource{
Expand Down
5 changes: 5 additions & 0 deletions pkg/controller/appdefinition/testdata/router/expected.golden
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ spec:
port: 8080
resources: {}
volumeMounts:
- mountPath: /etc/nginx/conf.d
name: confd
- mountPath: /etc/nginx/conf.d/nginx.conf
name: conf
readOnly: true
Expand All @@ -65,6 +67,9 @@ spec:
- key: taints.acorn.io/workload
operator: Exists
volumes:
- emptyDir:
medium: Memory
name: confd
- configMap:
name: router-name-30019cec
name: conf
Expand Down
10 changes: 10 additions & 0 deletions pkg/controller/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,5 +97,15 @@ func (c *Controller) initData(ctx context.Context) error {
if err != nil {
return err
}
if system.IsLocal() {
err = c.apply.Ensure(ctx, &v1.ProjectInstance{
ObjectMeta: metav1.ObjectMeta{
Name: "local",
},
})
if err != nil {
return err
}
}
return config.Init(ctx, c.client)
}
5 changes: 5 additions & 0 deletions pkg/controller/local/pods.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,10 @@ func DeletePods(req router.Request, resp router.Response) error {
return req.Client.Delete(req.Ctx, pod)
}
}
for _, container := range pod.Spec.InitContainers {
if container.Image == system.LocalImage {
return req.Client.Delete(req.Ctx, pod)
}
}
return nil
}
100 changes: 58 additions & 42 deletions pkg/controller/local/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/docker/docker/api/types/container"
"github.com/docker/docker/client"
"github.com/docker/go-connections/nat"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
Expand Down Expand Up @@ -57,55 +58,70 @@ func (c *Handler) ProvisionPorts(req router.Request, resp router.Response) error
continue
}

pod := &corev1.Pod{
deploy := &appsv1.Deployment{
ObjectMeta: metav1.ObjectMeta{
Name: name,
Namespace: system.Namespace,
Labels: map[string]string{
"app": "klipper-lb",
},
},
Spec: corev1.PodSpec{
Containers: []corev1.Container{
{
Name: "klipper-lb",
Command: []string{"klipper-lb"},
Image: system.LocalImage,
SecurityContext: &corev1.SecurityContext{
Capabilities: &corev1.Capabilities{
Add: []corev1.Capability{
"NET_ADMIN",
},
},
},
Env: []corev1.EnvVar{
{
Name: "SRC_PORT",
Value: fmt.Sprint(port.Port),
},
{
Name: "SRC_RANGES",
Value: "0.0.0.0/0",
},
{
Name: "DEST_PROTO",
Value: string(port.Protocol),
},
{
Name: "DEST_PORT",
Value: fmt.Sprint(port.Port),
},
{
Name: "DEST_IPS",
Value: svc.Spec.ClusterIP,
},
Spec: appsv1.DeploymentSpec{
Selector: metav1.SetAsLabelSelector(map[string]string{
"app": "klipper-lb",
}),
Strategy: appsv1.DeploymentStrategy{
Type: appsv1.RecreateDeploymentStrategyType,
},
Template: corev1.PodTemplateSpec{
ObjectMeta: metav1.ObjectMeta{
Labels: map[string]string{
"app": "klipper-lb",
},
Ports: []corev1.ContainerPort{
},
Spec: corev1.PodSpec{
Containers: []corev1.Container{
{
Name: "port",
HostPort: port.Port,
ContainerPort: port.Port,
Protocol: port.Protocol,
Name: "klipper-lb",
Command: []string{"klipper-lb"},
Image: system.LocalImage,
SecurityContext: &corev1.SecurityContext{
Capabilities: &corev1.Capabilities{
Add: []corev1.Capability{
"NET_ADMIN",
},
},
},
Env: []corev1.EnvVar{
{
Name: "SRC_PORT",
Value: fmt.Sprint(port.Port),
},
{
Name: "SRC_RANGES",
Value: "0.0.0.0/0",
},
{
Name: "DEST_PROTO",
Value: string(port.Protocol),
},
{
Name: "DEST_PORT",
Value: fmt.Sprint(port.Port),
},
{
Name: "DEST_IPS",
Value: svc.Spec.ClusterIP,
},
},
Ports: []corev1.ContainerPort{
{
Name: "port",
HostPort: port.Port,
ContainerPort: port.Port,
Protocol: port.Protocol,
},
},
},
},
},
Expand All @@ -114,8 +130,8 @@ func (c *Handler) ProvisionPorts(req router.Request, resp router.Response) error
}

// Patch inline now, otherwise baaah will fight with the changes the webhook makes
webhook.PatchPodSpec(&pod.Spec)
resp.Objects(pod)
webhook.PatchPodSpec(&deploy.Spec.Template.Spec)
resp.Objects(deploy)

svc.Status.LoadBalancer.Ingress = []corev1.LoadBalancerIngress{
{
Expand Down
4 changes: 4 additions & 0 deletions pkg/controller/local/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ func createFolder(req router.Request, resp router.Response) error {
return err
}

if err := os.Chmod(path, 0777); err != nil {
return err
}

err := apply.New(req.Client).Ensure(req.Ctx, &corev1.PersistentVolume{
ObjectMeta: metav1.ObjectMeta{
Name: pvName,
Expand Down
Loading

0 comments on commit e0dc013

Please sign in to comment.