Skip to content

Commit c3adda0

Browse files
authored
Fn cli multi arch changes (#1596)
* adding support for architectures parameter
1 parent d55e01a commit c3adda0

File tree

148 files changed

+8268
-8857
lines changed

Some content is hidden

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

148 files changed

+8268
-8857
lines changed

.circleci/config.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@ version: 2
22
jobs:
33
build:
44
machine:
5-
image: circleci/classic:201708-01
5+
image: ubuntu-2004:202101-01
66
working_directory: ~/go/src/github.com/fnproject/fn
77
environment: # apparently expansion doesn't work here yet: https://discuss.circleci.com/t/environment-variable-expansion-in-working-directory/11322
8+
- GO111MODULE=on
89
- GOPATH=/home/circleci/go
10+
- GOFLAGS=-mod=vendor
911
- GOVERSION=1.12.1
1012
- OS=linux
1113
- ARCH=amd64
@@ -34,6 +36,7 @@ jobs:
3436
- run: git config diff.renamelimit 65535
3537
# NOTE: if GOFLAGS and GOMODULE are set, gosec will be noisy. unset them (run this before any 'make' command)
3638
- run: |
39+
GOPATH=/home/circleci/go:$GOPATH
3740
wget -O - -q https://raw.githubusercontent.com/securego/gosec/master/install.sh | sh -s -- -b $GOPATH/bin 1.2.0
3841
$GOPATH/bin/gosec -quiet -severity medium ./...
3942

api/agent/agent_repo_test.go

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,8 @@ func getFakeDocker(t *testing.T) (*httptest.Server, func()) {
108108
return
109109
}
110110
w.Header().Set("Content-Type", `application/vnd.docker.distribution.manifest.list.v2+json`)
111-
w.Header().Set("Docker-Content-Digest", `sha256:0553537fa07e2d97debdc40cdf6c6c9d0db7e57591bd86cd7c721f0161542a9e`)
111+
w.Header().Set("Docker-Content-Digest",
112+
`sha256:0553537fa07e2d97debdc40cdf6c6c9d0db7e57591bd86cd7c721f0161542a9e`)
112113
w.Header().Set("Docker-Distribution-Api-Version", `registry/2.0`)
113114
logStatus(r, 200)
114115
w.WriteHeader(200)
@@ -123,7 +124,8 @@ func getFakeDocker(t *testing.T) (*httptest.Server, func()) {
123124
return
124125
}
125126
w.Header().Set("Content-Type", `application/vnd.docker.distribution.manifest.v2+json`)
126-
w.Header().Set("Docker-Content-Digest", `sha256:1c80d00e6877ff57b9b941ab2cbc5bc1058c28294d7068074ccaecb29a1680d3`)
127+
w.Header().Set("Docker-Content-Digest",
128+
`sha256:1c80d00e6877ff57b9b941ab2cbc5bc1058c28294d7068074ccaecb29a1680d3`)
127129
w.Header().Set("Docker-Distribution-Api-Version", `registry/2.0`)
128130
logStatus(r, 200)
129131
w.WriteHeader(200)
@@ -156,6 +158,22 @@ func getFakeDocker(t *testing.T) (*httptest.Server, func()) {
156158
return
157159
}
158160

161+
if r.URL.String() == `/v2/foo/bar/manifests/sha256:0553537fa07e2d97debdc40cdf6c6c9d0db7e57591bd86cd7c721f0161542a9e` {
162+
if !manifestDone {
163+
manifestDone = true
164+
spitError(r, w, 429)
165+
return
166+
}
167+
w.Header().Set("Content-Type", `application/vnd.docker.distribution.manifest.v2+json`)
168+
w.Header().Set("Docker-Content-Digest",
169+
`sha256:1c80d00e6877ff57b9b941ab2cbc5bc1058c28294d7068074ccaecb29a1680d3`)
170+
w.Header().Set("Docker-Distribution-Api-Version", `registry/2.0`)
171+
logStatus(r, 200)
172+
w.WriteHeader(200)
173+
w.Write([]byte(manifest))
174+
return
175+
}
176+
159177
logStatus(r, 500)
160178
w.WriteHeader(500)
161179
return

api/agent/drivers/docker/docker_client.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//go:build go1.7
12
// +build go1.7
23

34
package docker

api/agent/iofs_notlinux.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//go:build !linux
12
// +build !linux
23

34
package agent

api/common/unix_logging.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//go:build !windows && !nacl && !plan9
12
// +build !windows,!nacl,!plan9
23

34
package common

api/common/win_logging.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//go:build !linux && !darwin
12
// +build !linux,!darwin
23

34
package common
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
package migrations
2+
3+
import (
4+
"context"
5+
"database/sql"
6+
"github.com/fnproject/fn/api/models"
7+
8+
"github.com/fnproject/fn/api/datastore/sql/migratex"
9+
"github.com/jmoiron/sqlx"
10+
)
11+
12+
func up25(ctx context.Context, tx *sqlx.Tx) error {
13+
14+
// Firstly add a new column shape
15+
_, err := tx.ExecContext(ctx, "ALTER TABLE apps ADD shape TEXT;")
16+
if err != nil {
17+
return err
18+
}
19+
20+
rows, err := tx.QueryxContext(ctx, "SELECT id FROM apps;")
21+
if err != nil {
22+
return err
23+
}
24+
25+
res := []*models.App{}
26+
for rows.Next() {
27+
28+
var app models.App
29+
err := rows.StructScan(&app)
30+
if err != nil {
31+
if err == sql.ErrNoRows {
32+
return nil
33+
}
34+
return err
35+
}
36+
// Set shape default value as empty string in order to avoid sql scan errors
37+
app.Shape = ""
38+
res = append(res, &app)
39+
}
40+
err = rows.Close()
41+
if err != nil {
42+
return err
43+
}
44+
45+
if err := rows.Err(); err != nil {
46+
return err
47+
}
48+
49+
for _, app := range res {
50+
query := tx.Rebind(`UPDATE apps SET shape=:shape WHERE id=:id`)
51+
_, err = tx.NamedExecContext(ctx, query, app)
52+
if err != nil {
53+
return err
54+
}
55+
}
56+
return nil
57+
}
58+
59+
func down25(ctx context.Context, tx *sqlx.Tx) error {
60+
_, err := tx.ExecContext(ctx, "ALTER TABLE apps DROP COLUMN shape;")
61+
return err
62+
}
63+
64+
func init() {
65+
Migrations = append(Migrations, &migratex.MigFields{
66+
VersionFunc: vfunc(25),
67+
UpFunc: up25,
68+
DownFunc: down25,
69+
})
70+
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
package migrations
2+
3+
import (
4+
"context"
5+
"database/sql"
6+
"github.com/fnproject/fn/api/models"
7+
8+
"github.com/fnproject/fn/api/datastore/sql/migratex"
9+
"github.com/jmoiron/sqlx"
10+
)
11+
12+
func up26(ctx context.Context, tx *sqlx.Tx) error {
13+
14+
// Firstly add a new column shape
15+
_, err := tx.ExecContext(ctx, "ALTER TABLE fns ADD shape TEXT;")
16+
if err != nil {
17+
return err
18+
}
19+
20+
rows, err := tx.QueryxContext(ctx, "SELECT id,app_id FROM fns;")
21+
if err != nil {
22+
return err
23+
}
24+
25+
res := []*models.Fn{}
26+
for rows.Next() {
27+
28+
var fn models.Fn
29+
err := rows.StructScan(&fn)
30+
if err != nil {
31+
if err == sql.ErrNoRows {
32+
return nil
33+
}
34+
return err
35+
}
36+
// Set shape default value as empty string in order to avoid sql scan errors
37+
fn.Shape = ""
38+
res = append(res, &fn)
39+
}
40+
err = rows.Close()
41+
if err != nil {
42+
return err
43+
}
44+
45+
if err := rows.Err(); err != nil {
46+
return err
47+
}
48+
49+
for _, app := range res {
50+
query := tx.Rebind(`UPDATE fns SET shape=:shape WHERE id=:id and app_id=:app_id`)
51+
_, err = tx.NamedExecContext(ctx, query, app)
52+
if err != nil {
53+
return err
54+
}
55+
}
56+
return nil
57+
}
58+
59+
func down26(ctx context.Context, tx *sqlx.Tx) error {
60+
_, err := tx.ExecContext(ctx, "ALTER TABLE fns DROP COLUMN shape;")
61+
return err
62+
}
63+
64+
func init() {
65+
Migrations = append(Migrations, &migratex.MigFields{
66+
VersionFunc: vfunc(26),
67+
UpFunc: up26,
68+
DownFunc: down26,
69+
})
70+
}

api/datastore/sql/sql.go

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ import (
3131
// fields not contiguous with other fields and this field is a fixed size,
3232
// we'll get better locality with varchar. it's not terribly easy to do this
3333
// with migrations (sadly, need complex transaction)
34-
3534
var tables = [...]string{
3635
`CREATE TABLE IF NOT EXISTS apps (
3736
id varchar(256) NOT NULL PRIMARY KEY,
@@ -40,7 +39,8 @@ var tables = [...]string{
4039
annotations text NOT NULL,
4140
syslog_url text,
4241
created_at varchar(256),
43-
updated_at varchar(256)
42+
updated_at varchar(256),
43+
shape text
4444
);`,
4545

4646
`CREATE TABLE IF NOT EXISTS triggers (
@@ -68,15 +68,16 @@ var tables = [...]string{
6868
annotations text NOT NULL,
6969
created_at varchar(256) NOT NULL,
7070
updated_at varchar(256) NOT NULL,
71+
shape text,
7172
CONSTRAINT name_app_id_unique UNIQUE (app_id, name)
7273
);`,
7374
}
7475

7576
const (
76-
appIDSelector = `SELECT id, name, config, annotations, syslog_url, created_at, updated_at FROM apps WHERE id=?`
77+
appIDSelector = `SELECT id, name, config, annotations, syslog_url, created_at, updated_at, shape FROM apps WHERE id=?`
7778
ensureAppSelector = `SELECT id FROM apps WHERE name=?`
7879

79-
fnSelector = `SELECT id,name,app_id,image,memory,timeout,idle_timeout,config,annotations,created_at,updated_at FROM fns`
80+
fnSelector = `SELECT id,name,app_id,image,memory,timeout,idle_timeout,config,annotations,created_at,updated_at,shape FROM fns`
8081
fnIDSelector = fnSelector + ` WHERE id=?`
8182

8283
triggerSelector = `SELECT id,name,app_id,fn_id,type,source,annotations,created_at,updated_at FROM triggers`
@@ -321,7 +322,8 @@ func (ds *SQLStore) InsertApp(ctx context.Context, newApp *models.App) (*models.
321322
annotations,
322323
syslog_url,
323324
created_at,
324-
updated_at
325+
updated_at,
326+
shape
325327
)
326328
VALUES (
327329
:id,
@@ -330,8 +332,10 @@ func (ds *SQLStore) InsertApp(ctx context.Context, newApp *models.App) (*models.
330332
:annotations,
331333
:syslog_url,
332334
:created_at,
333-
:updated_at
335+
:updated_at,
336+
:shape
334337
);`)
338+
335339
_, err := ds.db.NamedExecContext(ctx, query, app)
336340
if err != nil {
337341
if ds.helper.IsDuplicateKeyError(err) {
@@ -369,8 +373,8 @@ func (ds *SQLStore) UpdateApp(ctx context.Context, newapp *models.App) (*models.
369373
if err != nil {
370374
return err
371375
}
372-
373376
query = tx.Rebind(`UPDATE apps SET config=:config, annotations=:annotations, syslog_url=:syslog_url, updated_at=:updated_at WHERE name=:name`)
377+
374378
res, err := tx.NamedExecContext(ctx, query, app)
375379
if err != nil {
376380
return err
@@ -445,7 +449,8 @@ func (ds *SQLStore) GetApps(ctx context.Context, filter *models.AppFilter) (*mod
445449
return nil, err
446450
}
447451
/* #nosec */
448-
query = ds.db.Rebind(fmt.Sprintf("SELECT DISTINCT id, name, config, annotations, syslog_url, created_at, updated_at FROM apps %s", query))
452+
query = ds.db.Rebind(fmt.Sprintf("SELECT DISTINCT id, name, config, annotations, syslog_url, created_at, updated_at, shape FROM apps %s", query))
453+
449454
rows, err := ds.db.QueryxContext(ctx, query, args...)
450455
if err != nil {
451456
return nil, err
@@ -496,6 +501,19 @@ func (ds *SQLStore) InsertFn(ctx context.Context, newFn *models.Fn) (*models.Fn,
496501
}
497502
}
498503

504+
var app models.App
505+
query = tx.Rebind(appIDSelector)
506+
row := tx.QueryRowxContext(ctx, query, fn.AppID)
507+
508+
if err := row.StructScan(&app); err != nil {
509+
if err == sql.ErrNoRows {
510+
return models.ErrAppsNotFound
511+
}
512+
}
513+
514+
//Setting the fn shape same as the application shape
515+
fn.Shape = app.Shape
516+
499517
query = tx.Rebind(`INSERT INTO fns (
500518
id,
501519
name,
@@ -507,7 +525,8 @@ func (ds *SQLStore) InsertFn(ctx context.Context, newFn *models.Fn) (*models.Fn,
507525
config,
508526
annotations,
509527
created_at,
510-
updated_at
528+
updated_at,
529+
shape
511530
)
512531
VALUES (
513532
:id,
@@ -520,7 +539,8 @@ func (ds *SQLStore) InsertFn(ctx context.Context, newFn *models.Fn) (*models.Fn,
520539
:config,
521540
:annotations,
522541
:created_at,
523-
:updated_at
542+
:updated_at,
543+
:shape
524544
);`)
525545

526546
_, err = tx.NamedExecContext(ctx, query, fn)
@@ -565,7 +585,8 @@ func (ds *SQLStore) UpdateFn(ctx context.Context, fn *models.Fn) (*models.Fn, er
565585
idle_timeout = :idle_timeout,
566586
config = :config,
567587
annotations = :annotations,
568-
updated_at = :updated_at
588+
updated_at = :updated_at,
589+
shape = :shape
569590
WHERE id=:id;`)
570591

571592
_, err = tx.NamedExecContext(ctx, query, fn)

0 commit comments

Comments
 (0)