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

Commit 4ec066b

Browse files
Merge pull request #1614 from ibuildthecloud/dev-ports
Add dev ports and app locking
2 parents d8ae737 + 1dcf762 commit 4ec066b

File tree

64 files changed

+2696
-1812
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+2696
-1812
lines changed

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ FROM ghcr.io/acorn-io/images-mirror/rancher/klipper-lb:v0.3.5 AS klipper-lb
88
FROM ghcr.io/acorn-io/images-mirror/golang:1.20-alpine AS helper
99
WORKDIR /usr/src
1010
RUN apk -U add curl
11-
RUN curl -sfL https://github.com/loft-sh/devspace/archive/refs/tags/v5.18.5.tar.gz | tar xzf - --strip-components=1
11+
RUN curl -sfL https://github.com/loft-sh/devspace/archive/refs/tags/v6.3.2.tar.gz | tar xzf - --strip-components=1
1212
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
1313

1414
FROM ghcr.io/acorn-io/images-mirror/golang:1.20 AS build

go.mod

Lines changed: 116 additions & 150 deletions
Large diffs are not rendered by default.

go.sum

Lines changed: 270 additions & 1039 deletions
Large diffs are not rendered by default.

integration/dev/dev_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ func TestDev(t *testing.T) {
8181
}
8282

8383
_, err = appWatcher.ByName(ctx, ns.Name, "test-app", func(app *v1.AppInstance) (bool, error) {
84-
return app.Spec.Image != oldImage && app.Spec.Image != "", nil
84+
return app.Spec.Image == oldImage && app.Status.DevSession != nil && app.Status.DevSession.SpecOverride.Image != "", nil
8585
})
8686
if err != nil {
8787
t.Fatal(err)

integration/helper/controller.go

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"github.com/acorn-io/acorn/pkg/server"
2222
"github.com/acorn-io/acorn/pkg/system"
2323
"github.com/acorn-io/baaah/pkg/restconfig"
24+
minkserver "github.com/acorn-io/mink/pkg/server"
2425
"github.com/google/go-containerregistry/pkg/registry"
2526
uuid2 "github.com/google/uuid"
2627
"github.com/sirupsen/logrus"
@@ -126,13 +127,8 @@ func StartAPI(t *testing.T) *rest.Config {
126127
t.Fatal(err)
127128
}
128129

129-
srv := server.New()
130-
srv.Options.SecureServing.Listener = l
131-
srv.Options.Authentication.TolerateInClusterLookupFailure = true
132-
cfg, err := srv.NewConfig("dev")
133-
if err != nil {
134-
t.Fatal(err)
135-
}
130+
opts := minkserver.DefaultOpts()
131+
opts.SecureServing.Listener = l
136132

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

161-
if err == nil {
162-
go func() {
163-
cfg.LocalRestConfig = restConfig
164-
err := srv.Run(context.Background(), cfg)
165-
t.Log("failed to start api", err)
166-
}()
157+
s, err := server.New(server.Config{
158+
LocalRestConfig: restConfig,
159+
DefaultOpts: opts,
160+
IgnoreStartFailure: true,
161+
})
162+
if err != nil {
163+
t.Fatal(err)
167164
}
168165

166+
go func() {
167+
err := s.Run(context.Background())
168+
t.Log("failed to start api", err)
169+
}()
170+
169171
restClient, err := rest.RESTClientFor(restConfig)
170172
if err != nil {
171173
t.Fatal(err)

integration/secrets/testdata/generated-json/Acornfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ jobs: {
1010
{
1111
"type": "basic",
1212
"data": {
13-
"key": "$(echo -n value | base64)",
14-
"pass": "$(echo -n $PASS | base64)"
13+
"key": "value",
14+
"pass": "$PASS"
1515
}
1616
}
1717
EOF

pkg/apis/api.acorn.io/v1/scheme.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ func AddToSchemeWithGV(scheme *runtime.Scheme, schemeGroupVersion schema.GroupVe
6565
&ImageAllowRuleList{},
6666
&Event{},
6767
&EventList{},
68+
&DevSession{},
69+
&DevSessionList{},
6870
)
6971

7072
// Add common types

pkg/apis/api.acorn.io/v1/types.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ func (in *App) GetRegion() string {
2626
return in.Status.Defaults.Region
2727
}
2828

29+
type Acornfile v1.AppSpec
30+
2931
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
3032

3133
type AppList struct {
@@ -571,3 +573,15 @@ type EventList struct {
571573
metav1.ListMeta `json:"metadata,omitempty"`
572574
Items []Event `json:"items"`
573575
}
576+
577+
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
578+
579+
type DevSession v1.DevSessionInstance
580+
581+
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
582+
583+
type DevSessionList struct {
584+
metav1.TypeMeta `json:",inline"`
585+
metav1.ListMeta `json:"metadata,omitempty"`
586+
Items []DevSession `json:"items"`
587+
}

pkg/apis/api.acorn.io/v1/zz_generated.deepcopy.go

Lines changed: 144 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/apis/internal.acorn.io/v1/appinstance.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@ type AppInstanceSpec struct {
8989
Annotations []ScopedLabel `json:"annotations,omitempty"`
9090
Image string `json:"image,omitempty"`
9191
Stop *bool `json:"stop,omitempty"`
92-
DevMode *bool `json:"devMode,omitempty"`
9392
Profiles []string `json:"profiles,omitempty"`
9493
Volumes []VolumeBinding `json:"volumes,omitempty"`
9594
Secrets []SecretBinding `json:"secrets,omitempty"`
@@ -119,12 +118,8 @@ func (in *AppInstanceSpec) GetNotifyUpgrade() bool {
119118
return in.NotifyUpgrade != nil && *in.NotifyUpgrade
120119
}
121120

122-
func (in *AppInstanceSpec) GetDevMode() bool {
123-
return in.DevMode != nil && *in.DevMode
124-
}
125-
126-
func (in *AppInstanceSpec) GetProfiles() []string {
127-
if in.GetDevMode() {
121+
func (in *AppInstanceSpec) GetProfiles(devMode bool) []string {
122+
if devMode {
128123
found := false
129124
for _, profile := range in.Profiles {
130125
if profile == "dev?" {
@@ -190,7 +185,12 @@ type AppColumns struct {
190185
Created string `json:"created,omitempty" column:"name=Created,jsonpath=.metadata.creationTimestamp"`
191186
}
192187

188+
func (a AppInstanceStatus) GetDevMode() bool {
189+
return a.DevSession != nil
190+
}
191+
193192
type AppInstanceStatus struct {
193+
DevSession *DevSessionInstanceSpec `json:"devSession,omitempty"`
194194
ObservedGeneration int64 `json:"observedGeneration,omitempty"`
195195
ObservedImageDigest string `json:"observedImageDigest,omitempty"`
196196
Columns AppColumns `json:"columns,omitempty"`

pkg/apis/internal.acorn.io/v1/appspec.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,6 @@ func (in PortBinding) Complete() PortBinding {
103103
}
104104

105105
func (in PortDef) FormatString(serviceName string) string {
106-
//in = in.Complete(in.ServiceName)
107106
buf := &strings.Builder{}
108107
if serviceName != "" {
109108
buf.WriteString(serviceName)
@@ -128,6 +127,7 @@ type PortDef struct {
128127
Hostname string `json:"hostname,omitempty"`
129128
Protocol Protocol `json:"protocol,omitempty"`
130129
Publish bool `json:"publish,omitempty"`
130+
Dev bool `json:"dev,omitempty"`
131131
Port int32 `json:"port,omitempty"`
132132
TargetPort int32 `json:"targetPort,omitempty"`
133133
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package v1
2+
3+
import metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
4+
5+
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
6+
7+
type DevSessionInstanceList struct {
8+
metav1.TypeMeta `json:",inline"`
9+
metav1.ListMeta `json:"metadata,omitempty"`
10+
Items []DevSessionInstance `json:"items"`
11+
}
12+
13+
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
14+
15+
type DevSessionInstance struct {
16+
metav1.TypeMeta `json:",inline"`
17+
metav1.ObjectMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`
18+
19+
Spec DevSessionInstanceSpec `json:"spec,omitempty"`
20+
Status DevSessionInstanceStatus `json:"status,omitempty"`
21+
}
22+
23+
type DevSessionInstanceSpec struct {
24+
Client DevSessionInstanceClient `json:"client,omitempty"`
25+
SessionTimeoutSeconds int32 `json:"sessionTimeoutSeconds,omitempty"`
26+
SessionStartTime metav1.Time `json:"sessionStartTime,omitempty"`
27+
SessionRenewTime metav1.Time `json:"sessionRenewTime,omitempty"`
28+
SpecOverride *AppInstanceSpec `json:"specOverride,omitempty"`
29+
}
30+
31+
type DevSessionInstanceStatus struct {
32+
Expired bool `json:"expired,omitempty"`
33+
Conditions []Condition `json:"conditions,omitempty"`
34+
}
35+
36+
type DevSessionInstanceClient struct {
37+
Hostname string `json:"hostname,omitempty"`
38+
ImageSource DevSessionImageSource `json:"imageSource,omitempty"`
39+
}
40+
41+
type DevSessionImageSource struct {
42+
Image string `json:"image,omitempty"`
43+
File string `json:"file,omitempty"`
44+
}
45+
46+
type DevSessionInstanceExpireAction struct {
47+
Stop bool `json:"stop,omitempty"`
48+
}

pkg/apis/internal.acorn.io/v1/scheme.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ func AddToScheme(scheme *runtime.Scheme) error {
3030
&ImageAllowRuleInstanceList{},
3131
&EventInstance{},
3232
&EventInstanceList{},
33+
&DevSessionInstance{},
34+
&DevSessionInstanceList{},
3335
)
3436

3537
// Add common types

pkg/apis/internal.acorn.io/v1/unmarshal.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -819,6 +819,11 @@ func (in *Ports) UnmarshalJSON(data []byte) error {
819819
}
820820
for _, port := range ports["publish"] {
821821
port.Publish = true
822+
port.Dev = false
823+
*in = append(*in, port)
824+
}
825+
for _, port := range ports["dev"] {
826+
port.Dev = true
822827
*in = append(*in, port)
823828
}
824829
return nil

0 commit comments

Comments
 (0)