Skip to content
This repository has been archived by the owner on Oct 9, 2023. It is now read-only.

Commit

Permalink
Upgrade go dependencies (#133)
Browse files Browse the repository at this point in the history
* Update stow version

Signed-off-by: Haytham Abuelfutuh <[email protected]>

* run unit tests on go 1.18

Signed-off-by: Haytham Abuelfutuh <[email protected]>

* Reset changes and only update stow

Signed-off-by: Haytham Abuelfutuh <[email protected]>

* Remove file-move-based change since fsnotify nolonger supports it

Signed-off-by: Haytham Abuelfutuh <[email protected]>

* Move to go 1.18 in gh wf

Signed-off-by: Haytham Abuelfutuh <[email protected]>

* use common lint wf

Signed-off-by: Haytham Abuelfutuh <[email protected]>

* install golangci-lang through curl

Signed-off-by: Haytham Abuelfutuh <[email protected]>

* move to go bin path

Signed-off-by: Haytham Abuelfutuh <[email protected]>

* fix lint

Signed-off-by: Haytham Abuelfutuh <[email protected]>

* use go 1.18

Signed-off-by: Haytham Abuelfutuh <[email protected]>

* another try

Signed-off-by: Haytham Abuelfutuh <[email protected]>

* Move problematic comments to Example() blocks

Signed-off-by: Haytham Abuelfutuh <[email protected]>

* more

Signed-off-by: Haytham Abuelfutuh <[email protected]>

* wip

Signed-off-by: Haytham Abuelfutuh <[email protected]>

* fix lint issues

Signed-off-by: Haytham Abuelfutuh <[email protected]>

Signed-off-by: Haytham Abuelfutuh <[email protected]>
  • Loading branch information
EngHabu authored Aug 30, 2022
1 parent 65025fd commit 61b06c7
Show file tree
Hide file tree
Showing 21 changed files with 1,006 additions and 1,007 deletions.
16 changes: 8 additions & 8 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on: pull_request

jobs:
tests-lint:
name: Run tests and lint
name: Run tests
runs-on: ubuntu-latest
steps:
- name: Checkout
Expand All @@ -13,7 +13,7 @@ jobs:
fetch-depth: "0"
- uses: actions/setup-go@v2
with:
go-version: '1.17'
go-version: '1.18'
- name: Unit Tests
run: make mod_download && make test_unit_codecov
- name: Push CodeCov
Expand All @@ -22,13 +22,13 @@ jobs:
file: coverage.txt
flags: unittests
fail_ci_if_error: true
- uses: actions/setup-go@v2
with:
go-version: '1.17'
- name: Lint
run: make install && make lint
- name: Bench tests
run: make install && make test_benchmark
lint:
name: Lint
uses: flyteorg/flytetools/.github/workflows/lint.yml@master
with:
go-version: '1.18'
test-generate-integrity:
name: Ensure go generate has run
runs-on: ubuntu-latest
Expand All @@ -39,7 +39,7 @@ jobs:
fetch-depth: "0"
- uses: actions/setup-go@v2
with:
go-version: '1.17'
go-version: '1.18'
- name: Go generate and diff
run: DELTA_CHECK=true make generate

293 changes: 169 additions & 124 deletions boilerplate/flyte/golang_support_tools/go.mod

Large diffs are not rendered by default.

1,259 changes: 649 additions & 610 deletions boilerplate/flyte/golang_support_tools/go.sum

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion boilerplate/flyte/golang_test_targets/download_tooling.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ set -e
tools=(
"github.com/vektra/mockery/cmd/mockery"
"github.com/flyteorg/flytestdlib/cli/pflags"
"github.com/golangci/golangci-lint/cmd/golangci-lint"
"github.com/alvaroloes/enumer"
"github.com/pseudomuto/protoc-gen-doc/cmd/protoc-gen-doc"
)
Expand All @@ -28,6 +27,8 @@ echo "Using temp directory ${tmp_dir}"
cp -R boilerplate/flyte/golang_support_tools/* $tmp_dir
pushd "$tmp_dir"

curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.49.0

for tool in "${tools[@]}"
do
echo "Installing ${tool}"
Expand Down
29 changes: 13 additions & 16 deletions cache/auto_refresh.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,14 @@ const (
Update
)

// Your implementation of this function for your cache instance is responsible for returning
// 1. The new Item, and
// 2. What action should be taken. The sync function has no insight into your object, and needs to be
// told explicitly if the new item is different from the old one.
// SyncFunc func type. Your implementation of this function for your cache instance is responsible for returning
// The new Item and what action should be taken. The sync function has no insight into your object, and needs to be
// told explicitly if the new item is different from the old one.
type SyncFunc func(ctx context.Context, batch Batch) (
updatedBatch []ItemSyncResponse, err error)

// Your implementation of this function for your cache instance is responsible for subdividing
// the list of cache items into batches.
// CreateBatchesFunc is a func type. Your implementation of this function for your cache instance is responsible for
// subdividing the list of cache items into batches.
type CreateBatchesFunc func(ctx context.Context, snapshot []ItemWrapper) (batches []Batch, err error)

type itemWrapper struct {
Expand Down Expand Up @@ -202,10 +201,8 @@ func (w *autoRefresh) DeleteDelayed(id ItemID) error {
return nil
}

// This function is called internally by its own timer. Roughly, it will,
// - List keys
// - Create batches of keys based on createBatchesCb
// - Enqueue all the batches into the workqueue
// This function is called internally by its own timer. Roughly, it will list keys, create batches of keys based on
// createBatchesCb and, enqueue all the batches into the workqueue.
func (w *autoRefresh) enqueueBatches(ctx context.Context) error {
keys := w.lruMap.Keys()
w.metrics.Size.Set(float64(len(keys)))
Expand Down Expand Up @@ -236,15 +233,15 @@ func (w *autoRefresh) enqueueBatches(ctx context.Context) error {
}

// There are w.parallelizm instances of this function running all the time, each one will:
// - Retrieve an item from the workqueue
// - For each batch of the keys, call syncCb, which tells us if the items have been updated
// - If any has, then overwrite the item in the cache.
// - Retrieve an item from the workqueue
// - For each batch of the keys, call syncCb, which tells us if the items have been updated
// -- If any has, then overwrite the item in the cache.
//
// What happens when the number of things that a user is trying to keep track of exceeds the size
// of the cache? Trivial case where the cache is size 1 and we're trying to keep track of two things.
// * Plugin asks for update on item 1 - cache evicts item 2, stores 1 and returns it unchanged
// * Plugin asks for update on item 2 - cache evicts item 1, stores 2 and returns it unchanged
// * Sync loop updates item 2, repeat
// * Plugin asks for update on item 1 - cache evicts item 2, stores 1 and returns it unchanged
// * Plugin asks for update on item 2 - cache evicts item 1, stores 2 and returns it unchanged
// * Sync loop updates item 2, repeat
func (w *autoRefresh) sync(ctx context.Context) (err error) {
defer func() {
var isErr bool
Expand Down
6 changes: 3 additions & 3 deletions cli/pflags/api/tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ const (
JSONTagName = "json"
)

// Represents parsed PFlag Go-struct tag.
// Tag represents parsed PFlag Go-struct tag.
// type Foo struct {
// StringValue string `json:"str" pflag:"\"hello world\",This is a string value"`
// StringValue string `json:"str" pflag:"\"hello world\",This is a string value"`
// }
// Name will be "str", Default value is "hello world" and Usage is "This is a string value"
type Tag struct {
Expand All @@ -24,7 +24,7 @@ type Tag struct {
Usage string
}

// Parses tag. Name is computed from json tag, defaultvalue is the name of the pflag tag and usage is the concatenation
// ParseTag parses tag. Name is computed from json tag, defaultvalue is the name of the pflag tag and usage is the concatenation
// of all options for pflag tag.
// e.g. `json:"name" pflag:"2,this is a useful param"`
func ParseTag(tag string) (t Tag, err error) {
Expand Down
57 changes: 15 additions & 42 deletions config/tests/accessor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func getRandInt() uint64 {
return binary.BigEndian.Uint64(b)
}

func tempFileName(pattern string) string {
func tempFileName(dir, pattern string) string {
// TODO: Remove this hack after we use Go1.11 everywhere:
// https://github.com/golang/go/commit/191efbc419d7e5dec842c20841f6f716da4b561d

Expand All @@ -50,7 +50,11 @@ func tempFileName(pattern string) string {
prefix = pattern
}

return filepath.Join(os.TempDir(), prefix+k8sRand.String(6)+suffix)
if len(dir) == 0 {
dir = os.TempDir()
}

return filepath.Join(dir, prefix+k8sRand.String(6)+suffix)
}

func populateConfigData(configPath string) (TestConfig, error) {
Expand Down Expand Up @@ -434,7 +438,7 @@ func TestAccessor_UpdateConfig(t *testing.T) {
})

t.Run(fmt.Sprintf("[%v] Change handler", provider(config.Options{}).ID()), func(t *testing.T) {
configFile := tempFileName("config-*.yaml")
configFile := tempFileName("", "config-*.yaml")
defer func() { assert.NoError(t, os.Remove(configFile)) }()
cfg, err := populateConfigData(configFile)
assert.NoError(t, err)
Expand All @@ -458,38 +462,6 @@ func TestAccessor_UpdateConfig(t *testing.T) {
assert.True(t, called)
})

t.Run(fmt.Sprintf("[%v] Change handler on change", provider(config.Options{}).ID()), func(t *testing.T) {
configFile := tempFileName("config-*.yaml")
defer func() { assert.NoError(t, os.Remove(configFile)) }()
_, err := populateConfigData(configFile)
assert.NoError(t, err)

reg := config.NewRootSection()
_, err = reg.RegisterSection(MyComponentSectionKey, &MyComponentConfig{})
assert.NoError(t, err)

opts := config.Options{
SearchPaths: []string{configFile},
RootSection: reg,
}
v := provider(opts)
err = v.UpdateConfig(context.TODO())
assert.NoError(t, err)

r := reg.GetSection(MyComponentSectionKey).GetConfig().(*MyComponentConfig)
firstValue := r.StringValue

_, err = populateConfigData(configFile)
assert.NoError(t, err)

// Wait enough for the file change notification to propagate.
time.Sleep(5 * time.Second)

r = reg.GetSection(MyComponentSectionKey).GetConfig().(*MyComponentConfig)
secondValue := r.StringValue
assert.NotEqual(t, firstValue, secondValue)
})

t.Run(fmt.Sprintf("[%v] Change handler k8s configmaps", provider(config.Options{}).ID()), func(t *testing.T) {
reg := config.NewRootSection()
section, err := reg.RegisterSection(MyComponentSectionKey, &MyComponentConfig{})
Expand Down Expand Up @@ -562,7 +534,7 @@ func TestAccessor_UpdateConfig(t *testing.T) {
}

func changeSymLink(targetPath, symLink string) error {
tmpLink := tempFileName("temp-sym-link-*")
tmpLink := tempFileName("", "temp-sym-link-*")
if runtime.GOOS == "windows" {
// #nosec G204
err := exec.Command("mklink", filepath.Clean(tmpLink), filepath.Clean(targetPath)).Run()
Expand All @@ -586,12 +558,13 @@ func changeSymLink(targetPath, symLink string) error {
return exec.Command("ln", "-sfn", filepath.Clean(targetPath), filepath.Clean(symLink)).Run()
}

// 1. Create Dir structure:
// |_ data1
// |_ config.yaml
// |_ data (symlink for data1)
// |_ config.yaml (symlink for data/config.yaml -recursively a symlink of data1/config.yaml)
func newSymlinkedConfigFile(t *testing.T) (watchDir, configFile string, cleanup func()) {
// 1. Create Dir structure:
// |_ data1
// |_ config.yaml
// |_ data (symlink for data1)
// |_ config.yaml (symlink for data/config.yaml -recursively a symlink of data1/config.yaml)

watchDir, err := ioutil.TempDir("", "config-test-")
assert.NoError(t, err)

Expand Down Expand Up @@ -686,7 +659,7 @@ func runEqualTest(t *testing.T, accessor accessorCreatorFn, expected interface{}

raw, err := yaml.Marshal(m)
assert.NoError(t, err)
f := tempFileName("test_type_*.yaml")
f := tempFileName("", "test_type_*.yaml")
assert.NoError(t, err)
defer func() { assert.NoError(t, os.Remove(f)) }()

Expand Down
9 changes: 1 addition & 8 deletions futures/future.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
// This module implements a simple Async Futures for golang
// Usage:
// f := NewAsyncFuture(childCtx, func(ctx2 context.Context) (interface{}, error) {
// can do large async / non blocking work
// return ...
// }
// f.Ready() // can be checked for completion
// f.Get() .. will block till the given sub-routine returns
// Package futures implements a simple Async Futures for golang
package futures

import (
Expand Down
12 changes: 12 additions & 0 deletions futures/future_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,18 @@ import (
"github.com/stretchr/testify/assert"
)

func Example() {
ctx := context.Background()
f := NewAsyncFuture(ctx, func(ctx2 context.Context) (interface{}, error) {
// can do large async / non-blocking work
time.Sleep(time.Second)
return "hello", nil
})

f.Ready() // can be checked for completion
_, _ = f.Get(ctx) // will block till the given sub-routine returns
}

func TestNewSyncFuture(t *testing.T) {
type args struct {
val interface{}
Expand Down
42 changes: 22 additions & 20 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
module github.com/flyteorg/flytestdlib

go 1.17
go 1.18

require (
github.com/aws/aws-sdk-go v1.43.37
github.com/aws/aws-sdk-go v1.44.2
github.com/benlaurie/objecthash v0.0.0-20180202135721-d1e3d6079fc1
github.com/coocood/freecache v1.1.1
github.com/ernesto-jimenez/gogen v0.0.0-20180125220232-d7d4131e6607
github.com/fatih/color v1.13.0
github.com/fatih/structtag v1.2.0
github.com/flyteorg/stow v0.3.4
github.com/flyteorg/stow v0.3.6
github.com/fsnotify/fsnotify v1.5.1
github.com/ghodss/yaml v1.0.0
github.com/go-test/deep v1.0.7
Expand All @@ -25,7 +25,7 @@ require (
github.com/spf13/viper v1.11.0
github.com/stretchr/testify v1.7.1
golang.org/x/time v0.0.0-20201208040808-7e3f01d25324
golang.org/x/tools v0.1.10
golang.org/x/tools v0.1.12
google.golang.org/protobuf v1.28.0
gorm.io/gorm v1.22.4
k8s.io/api v0.20.2
Expand All @@ -34,16 +34,16 @@ require (
)

require (
cloud.google.com/go v0.100.2 // indirect
cloud.google.com/go/compute v1.5.0 // indirect
cloud.google.com/go v0.101.0 // indirect
cloud.google.com/go/compute v1.6.1 // indirect
cloud.google.com/go/iam v0.3.0 // indirect
cloud.google.com/go/storage v1.14.0 // indirect
github.com/Azure/azure-sdk-for-go v62.3.0+incompatible // indirect
github.com/Azure/azure-sdk-for-go/sdk/azcore v0.21.1 // indirect
github.com/Azure/azure-sdk-for-go/sdk/internal v0.8.3 // indirect
github.com/Azure/azure-sdk-for-go/sdk/storage/azblob v0.3.0 // indirect
cloud.google.com/go/storage v1.22.0 // indirect
github.com/Azure/azure-sdk-for-go v63.4.0+incompatible // indirect
github.com/Azure/azure-sdk-for-go/sdk/azcore v0.23.1 // indirect
github.com/Azure/azure-sdk-for-go/sdk/internal v0.9.2 // indirect
github.com/Azure/azure-sdk-for-go/sdk/storage/azblob v0.4.0 // indirect
github.com/Azure/go-autorest v14.2.0+incompatible // indirect
github.com/Azure/go-autorest/autorest v0.11.25 // indirect
github.com/Azure/go-autorest/autorest v0.11.27 // indirect
github.com/Azure/go-autorest/autorest/adal v0.9.18 // indirect
github.com/Azure/go-autorest/autorest/date v0.3.0 // indirect
github.com/Azure/go-autorest/logger v0.2.1 // indirect
Expand All @@ -55,10 +55,12 @@ require (
github.com/go-logr/logr v0.4.0 // indirect
github.com/gofrs/uuid v4.2.0+incompatible // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang-jwt/jwt/v4 v4.2.0 // indirect
github.com/golang-jwt/jwt/v4 v4.4.1 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/google/go-cmp v0.5.8 // indirect
github.com/google/gofuzz v1.1.0 // indirect
github.com/googleapis/gax-go/v2 v2.3.0 // indirect
github.com/googleapis/go-type-adapters v1.0.0 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
Expand All @@ -82,17 +84,17 @@ require (
github.com/stretchr/objx v0.3.0 // indirect
github.com/subosito/gotenv v1.2.0 // indirect
go.opencensus.io v0.23.0 // indirect
golang.org/x/crypto v0.0.0-20220411220226-7b82a4e95df4 // indirect
golang.org/x/mod v0.6.0-dev.0.20220106191415-9b9b3d81d5e3 // indirect
golang.org/x/net v0.0.0-20220412020605-290c469a71a5 // indirect
golang.org/x/crypto v0.0.0-20220427172511-eb4f295cb31f // indirect
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 // indirect
golang.org/x/net v0.0.0-20220722155237-a158d28d115b // indirect
golang.org/x/oauth2 v0.0.0-20220411215720-9780585627b5 // indirect
golang.org/x/sys v0.0.0-20220412211240-33da011f77ad // indirect
golang.org/x/sys v0.0.0-20220829200755-d48e67d00261 // indirect
golang.org/x/text v0.3.7 // indirect
golang.org/x/xerrors v0.0.0-20220411194840-2f41105eb62f // indirect
google.golang.org/api v0.74.0 // indirect
google.golang.org/api v0.76.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto v0.0.0-20220407144326-9054f6ed7bac // indirect
google.golang.org/grpc v1.45.0 // indirect
google.golang.org/genproto v0.0.0-20220426171045-31bebdecfb46 // indirect
google.golang.org/grpc v1.46.0 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/ini.v1 v1.66.4 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
Expand Down
Loading

0 comments on commit 61b06c7

Please sign in to comment.