Skip to content

Commit

Permalink
Devflow, boilerplate, improved code, formatting and bug fixes (flyteo…
Browse files Browse the repository at this point in the history
  • Loading branch information
kumare3 authored and austin362667 committed May 7, 2024
1 parent 2c56ff7 commit e659074
Show file tree
Hide file tree
Showing 40 changed files with 2,048 additions and 204 deletions.
26 changes: 0 additions & 26 deletions flytectl/.github/workflows/release.yml

This file was deleted.

1 change: 1 addition & 0 deletions flytectl/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ vendor
bin
.DS_Store
_test
./config.yaml
4 changes: 2 additions & 2 deletions flytectl/.golangci.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# WARNING: THIS FILE IS MANAGED IN THE 'BOILERPLATE' REPO AND COPIED TO OTHER REPOSITORIES.
# ONLY EDIT THIS FILE FROM WITHIN THE 'LYFT/BOILERPLATE' REPOSITORY:
#
#
# TO OPT OUT OF UPDATES, SEE https://github.com/lyft/boilerplate/blob/master/Readme.rst

run:
Expand All @@ -27,4 +27,4 @@ linters:
- unconvert
- unparam
- unused
- varcheck
- varcheck
12 changes: 11 additions & 1 deletion flytectl/Makefile
Original file line number Diff line number Diff line change
@@ -1,2 +1,12 @@
export REPOSITORY=flytectl
include boilerplate/lyft/golang_test_targets/Makefile

generate:
go test github.com/lyft/flytectl/cmd --update
go test github.com/lyft/flytectl/cmd --update

compile:
go build -o bin/flytectl main.go

.PHONY: update_boilerplate
update_boilerplate:
@boilerplate/update.sh
22 changes: 22 additions & 0 deletions flytectl/adminutils/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package adminutils

import "github.com/lyft/flytestdlib/config"

//go:generate pflags Config

var (
defaultConfig = &Config{
MaxRecords: 500,
BatchSize: 100,
}
section = config.MustRegisterSection("adminutils", defaultConfig)
)

type Config struct {
MaxRecords int `json:"maxRecords" pflag:",Maximum number of records to retrieve."`
BatchSize int `json:"batchSize" pflag:",Maximum number of records to retrieve per call."`
}

func GetConfig() *Config {
return section.GetConfig().(*Config)
}
47 changes: 47 additions & 0 deletions flytectl/adminutils/config_flags.go

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

146 changes: 146 additions & 0 deletions flytectl/adminutils/config_flags_test.go

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

62 changes: 62 additions & 0 deletions flytectl/adminutils/iterator.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package adminutils

import (
"context"

"github.com/lyft/flyteidl/gen/pb-go/flyteidl/admin"
"google.golang.org/grpc"
)

type NamedEntityIDLister func(ctx context.Context, in *admin.NamedEntityIdentifierListRequest, opts ...grpc.CallOption) (*admin.NamedEntityIdentifierList, error)

type NamedEntityVisitor func(entities []*admin.NamedEntityIdentifier) error

type ListRequest struct {
Project string
Domain string
Filters string
}

func IterateThroughAllNamedEntities(ctx context.Context, lister NamedEntityIDLister, visitor NamedEntityVisitor, req ListRequest, opts ...grpc.CallOption) error {
adminReq := &admin.NamedEntityIdentifierListRequest{
Project: req.Project,
Domain: req.Domain,
Filters: req.Filters,
SortBy: &admin.Sort{
Key: "name",
Direction: admin.Sort_ASCENDING,
},
Limit: uint32(GetConfig().BatchSize),
}

i := 0
for i < GetConfig().MaxRecords {
res, err := lister(ctx, adminReq, opts...)
if err != nil {
return err
}
if len(res.Entities) != 0 {
if err := visitor(res.Entities); err != nil {
return err
}
}
i = i + len(res.Entities)
if len(res.Entities) == 0 || res.Token == "" {
break
}
adminReq.Token = res.Token
}
return nil
}

func GetAllNamedEntities(ctx context.Context, lister NamedEntityIDLister, req ListRequest, opts ...grpc.CallOption) ([]*admin.NamedEntityIdentifier, error) {
var allEntities []*admin.NamedEntityIdentifier
err := IterateThroughAllNamedEntities(ctx, lister, func(entities []*admin.NamedEntityIdentifier) error {
allEntities = append(allEntities, entities...)
return nil
}, req)
if err != nil {
return nil, err
}
return allEntities, nil
}
12 changes: 12 additions & 0 deletions flytectl/boilerplate/lyft/golang_support_tools/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module github.com/lyft/boilerplate

go 1.13

require (
github.com/alvaroloes/enumer v1.1.2
github.com/golangci/golangci-lint v1.22.2
github.com/lyft/flytestdlib v0.2.31
github.com/vektra/mockery v0.0.0-20181123154057-e78b021dcbb5
)

replace github.com/vektra/mockery => github.com/enghabu/mockery v0.0.0-20191009061720-9d0c8670c2f0

0 comments on commit e659074

Please sign in to comment.