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 #1614 from ibuildthecloud/dev-ports
Browse files Browse the repository at this point in the history
Add dev ports and app locking
  • Loading branch information
ibuildthecloud authored May 25, 2023
2 parents d8ae737 + 1dcf762 commit 4ec066b
Show file tree
Hide file tree
Showing 64 changed files with 2,696 additions and 1,812 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ FROM ghcr.io/acorn-io/images-mirror/rancher/klipper-lb:v0.3.5 AS klipper-lb
FROM ghcr.io/acorn-io/images-mirror/golang:1.20-alpine AS helper
WORKDIR /usr/src
RUN apk -U add curl
RUN curl -sfL https://github.com/loft-sh/devspace/archive/refs/tags/v5.18.5.tar.gz | tar xzf - --strip-components=1
RUN curl -sfL https://github.com/loft-sh/devspace/archive/refs/tags/v6.3.2.tar.gz | tar xzf - --strip-components=1
RUN --mount=type=cache,target=/go/pkg --mount=type=cache,target=/root/.cache/go-build CGO_ENABLED=0 go build -o /usr/local/bin/acorn-helper -ldflags "-s -w" ./helper

FROM ghcr.io/acorn-io/images-mirror/golang:1.20 AS build
Expand Down
266 changes: 116 additions & 150 deletions go.mod

Large diffs are not rendered by default.

1,309 changes: 270 additions & 1,039 deletions go.sum

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion integration/dev/dev_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func TestDev(t *testing.T) {
}

_, err = appWatcher.ByName(ctx, ns.Name, "test-app", func(app *v1.AppInstance) (bool, error) {
return app.Spec.Image != oldImage && app.Spec.Image != "", nil
return app.Spec.Image == oldImage && app.Status.DevSession != nil && app.Status.DevSession.SpecOverride.Image != "", nil
})
if err != nil {
t.Fatal(err)
Expand Down
28 changes: 15 additions & 13 deletions integration/helper/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"github.com/acorn-io/acorn/pkg/server"
"github.com/acorn-io/acorn/pkg/system"
"github.com/acorn-io/baaah/pkg/restconfig"
minkserver "github.com/acorn-io/mink/pkg/server"
"github.com/google/go-containerregistry/pkg/registry"
uuid2 "github.com/google/uuid"
"github.com/sirupsen/logrus"
Expand Down Expand Up @@ -126,13 +127,8 @@ func StartAPI(t *testing.T) *rest.Config {
t.Fatal(err)
}

srv := server.New()
srv.Options.SecureServing.Listener = l
srv.Options.Authentication.TolerateInClusterLookupFailure = true
cfg, err := srv.NewConfig("dev")
if err != nil {
t.Fatal(err)
}
opts := minkserver.DefaultOpts()
opts.SecureServing.Listener = l

kubeconfig := clientcmdapi.Config{
Clusters: map[string]*clientcmdapi.Cluster{
Expand All @@ -158,14 +154,20 @@ func StartAPI(t *testing.T) *rest.Config {
restConfig = restconfig.SetScheme(restConfig, scheme.Scheme)
restConfig.GroupVersion = &apiv1.SchemeGroupVersion

if err == nil {
go func() {
cfg.LocalRestConfig = restConfig
err := srv.Run(context.Background(), cfg)
t.Log("failed to start api", err)
}()
s, err := server.New(server.Config{
LocalRestConfig: restConfig,
DefaultOpts: opts,
IgnoreStartFailure: true,
})
if err != nil {
t.Fatal(err)
}

go func() {
err := s.Run(context.Background())
t.Log("failed to start api", err)
}()

restClient, err := rest.RESTClientFor(restConfig)
if err != nil {
t.Fatal(err)
Expand Down
4 changes: 2 additions & 2 deletions integration/secrets/testdata/generated-json/Acornfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ jobs: {
{
"type": "basic",
"data": {
"key": "$(echo -n value | base64)",
"pass": "$(echo -n $PASS | base64)"
"key": "value",
"pass": "$PASS"
}
}
EOF
Expand Down
2 changes: 2 additions & 0 deletions pkg/apis/api.acorn.io/v1/scheme.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ func AddToSchemeWithGV(scheme *runtime.Scheme, schemeGroupVersion schema.GroupVe
&ImageAllowRuleList{},
&Event{},
&EventList{},
&DevSession{},
&DevSessionList{},
)

// Add common types
Expand Down
14 changes: 14 additions & 0 deletions pkg/apis/api.acorn.io/v1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ func (in *App) GetRegion() string {
return in.Status.Defaults.Region
}

type Acornfile v1.AppSpec

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

type AppList struct {
Expand Down Expand Up @@ -571,3 +573,15 @@ type EventList struct {
metav1.ListMeta `json:"metadata,omitempty"`
Items []Event `json:"items"`
}

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

type DevSession v1.DevSessionInstance

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

type DevSessionList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []DevSession `json:"items"`
}
144 changes: 144 additions & 0 deletions pkg/apis/api.acorn.io/v1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions pkg/apis/internal.acorn.io/v1/appinstance.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ type AppInstanceSpec struct {
Annotations []ScopedLabel `json:"annotations,omitempty"`
Image string `json:"image,omitempty"`
Stop *bool `json:"stop,omitempty"`
DevMode *bool `json:"devMode,omitempty"`
Profiles []string `json:"profiles,omitempty"`
Volumes []VolumeBinding `json:"volumes,omitempty"`
Secrets []SecretBinding `json:"secrets,omitempty"`
Expand Down Expand Up @@ -119,12 +118,8 @@ func (in *AppInstanceSpec) GetNotifyUpgrade() bool {
return in.NotifyUpgrade != nil && *in.NotifyUpgrade
}

func (in *AppInstanceSpec) GetDevMode() bool {
return in.DevMode != nil && *in.DevMode
}

func (in *AppInstanceSpec) GetProfiles() []string {
if in.GetDevMode() {
func (in *AppInstanceSpec) GetProfiles(devMode bool) []string {
if devMode {
found := false
for _, profile := range in.Profiles {
if profile == "dev?" {
Expand Down Expand Up @@ -190,7 +185,12 @@ type AppColumns struct {
Created string `json:"created,omitempty" column:"name=Created,jsonpath=.metadata.creationTimestamp"`
}

func (a AppInstanceStatus) GetDevMode() bool {
return a.DevSession != nil
}

type AppInstanceStatus struct {
DevSession *DevSessionInstanceSpec `json:"devSession,omitempty"`
ObservedGeneration int64 `json:"observedGeneration,omitempty"`
ObservedImageDigest string `json:"observedImageDigest,omitempty"`
Columns AppColumns `json:"columns,omitempty"`
Expand Down
2 changes: 1 addition & 1 deletion pkg/apis/internal.acorn.io/v1/appspec.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ func (in PortBinding) Complete() PortBinding {
}

func (in PortDef) FormatString(serviceName string) string {
//in = in.Complete(in.ServiceName)
buf := &strings.Builder{}
if serviceName != "" {
buf.WriteString(serviceName)
Expand All @@ -128,6 +127,7 @@ type PortDef struct {
Hostname string `json:"hostname,omitempty"`
Protocol Protocol `json:"protocol,omitempty"`
Publish bool `json:"publish,omitempty"`
Dev bool `json:"dev,omitempty"`
Port int32 `json:"port,omitempty"`
TargetPort int32 `json:"targetPort,omitempty"`
}
Expand Down
48 changes: 48 additions & 0 deletions pkg/apis/internal.acorn.io/v1/devsession.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package v1

import metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

type DevSessionInstanceList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []DevSessionInstance `json:"items"`
}

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

type DevSessionInstance struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`

Spec DevSessionInstanceSpec `json:"spec,omitempty"`
Status DevSessionInstanceStatus `json:"status,omitempty"`
}

type DevSessionInstanceSpec struct {
Client DevSessionInstanceClient `json:"client,omitempty"`
SessionTimeoutSeconds int32 `json:"sessionTimeoutSeconds,omitempty"`
SessionStartTime metav1.Time `json:"sessionStartTime,omitempty"`
SessionRenewTime metav1.Time `json:"sessionRenewTime,omitempty"`
SpecOverride *AppInstanceSpec `json:"specOverride,omitempty"`
}

type DevSessionInstanceStatus struct {
Expired bool `json:"expired,omitempty"`
Conditions []Condition `json:"conditions,omitempty"`
}

type DevSessionInstanceClient struct {
Hostname string `json:"hostname,omitempty"`
ImageSource DevSessionImageSource `json:"imageSource,omitempty"`
}

type DevSessionImageSource struct {
Image string `json:"image,omitempty"`
File string `json:"file,omitempty"`
}

type DevSessionInstanceExpireAction struct {
Stop bool `json:"stop,omitempty"`
}
2 changes: 2 additions & 0 deletions pkg/apis/internal.acorn.io/v1/scheme.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ func AddToScheme(scheme *runtime.Scheme) error {
&ImageAllowRuleInstanceList{},
&EventInstance{},
&EventInstanceList{},
&DevSessionInstance{},
&DevSessionInstanceList{},
)

// Add common types
Expand Down
5 changes: 5 additions & 0 deletions pkg/apis/internal.acorn.io/v1/unmarshal.go
Original file line number Diff line number Diff line change
Expand Up @@ -819,6 +819,11 @@ func (in *Ports) UnmarshalJSON(data []byte) error {
}
for _, port := range ports["publish"] {
port.Publish = true
port.Dev = false
*in = append(*in, port)
}
for _, port := range ports["dev"] {
port.Dev = true
*in = append(*in, port)
}
return nil
Expand Down
Loading

0 comments on commit 4ec066b

Please sign in to comment.