Skip to content
This repository was archived by the owner on Aug 28, 2025. It is now read-only.

Commit f4da431

Browse files
vertex451Artem Shcherbatiuk
andauthored
fix config (#60)
Co-authored-by: Artem Shcherbatiuk <[email protected]>
1 parent 3c8ae32 commit f4da431

File tree

10 files changed

+35
-26
lines changed

10 files changed

+35
-26
lines changed

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ COPY --from=builder /app/main .
1313
USER 1001:1001
1414

1515
ENTRYPOINT ["./main"]
16-
CMD ["gql-gateway"]
16+
CMD ["gateway"]

Taskfile.yml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,17 @@ tasks:
5858
cmds:
5959
- task: lint
6060
- task: test
61+
62+
# start uses deprecated gateway
6163
start:
6264
cmds:
6365
- go run main.go start
6466

67+
# new gateway
6568
gateway:
6669
cmds:
67-
- go run main.go gql-gateway
70+
- go run main.go gateway
6871

69-
listen:
72+
listener:
7073
cmds:
71-
- go run main.go listen
74+
- go run main.go listener

cmd/gateway.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ import (
1919
)
2020

2121
var gatewayCmd = &cobra.Command{
22-
Use: "gql-gateway",
22+
Use: "gateway",
2323
Short: "Run the GQL Gateway",
24-
Example: "go run main.go start --watched-dir=./definitions",
24+
Example: "go run main.go gateway",
2525
RunE: func(cmd *cobra.Command, args []string) error {
2626
start := time.Now()
2727

cmd/listen.go renamed to cmd/listener.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ var (
4040
)
4141

4242
var listenCmd = &cobra.Command{
43-
Use: "listen",
44-
Example: "KUBECONFIG=<path to kubeconfig file> go run . listen",
43+
Use: "listener",
44+
Example: "KUBECONFIG=<path to kubeconfig file> go run . listener",
4545
PreRun: func(cmd *cobra.Command, args []string) {
4646
utilruntime.Must(clientgoscheme.AddToScheme(scheme))
4747

@@ -110,7 +110,7 @@ var listenCmd = &cobra.Command{
110110
reconcilerOpts := kcp.ReconcilerOpts{
111111
Scheme: scheme,
112112
Config: cfg,
113-
OpenAPIDefinitionsPath: opFlags.OpenAPIdefinitionsPath,
113+
OpenAPIDefinitionsPath: opFlags.OpenApiDefinitionsPath,
114114
}
115115

116116
newReconcilerFunc := kcp.ReconcilerFactory(opFlags)
File renamed without changes.

gateway/config/config.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,13 @@ import (
55
)
66

77
type Config struct {
8+
// common with listener
9+
OpenApiDefinitionsPath string `envconfig:"default=./bin/definitions"`
10+
EnableKcp bool `envconfig:"default=true,optional"`
11+
12+
// for gateway
813
Port string `envconfig:"default=8080,optional"`
914
LogLevel string `envconfig:"default=INFO,optional"`
10-
WatchedDir string `envconfig:"default=bin/definitions,required"`
11-
EnableKCP bool `envconfig:"default=true,optional"`
1215
LocalDevelopment bool `envconfig:"default=false,optional"`
1316
HandlerCfg HandlerConfig
1417
}

gateway/manager/manager.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,12 @@ func NewManager(log *logger.Logger, cfg *rest.Config, appCfg appConfig.Config) (
8282
watcher: watcher,
8383
}
8484

85-
err = m.watcher.Add(appCfg.WatchedDir)
85+
err = m.watcher.Add(appCfg.OpenApiDefinitionsPath)
8686
if err != nil {
8787
return nil, err
8888
}
8989

90-
files, err := filepath.Glob(filepath.Join(appCfg.WatchedDir, "*"))
90+
files, err := filepath.Glob(filepath.Join(appCfg.OpenApiDefinitionsPath, "*"))
9191
if err != nil {
9292
return nil, err
9393
}
@@ -160,7 +160,7 @@ func (s *Service) OnFileDeleted(filename string) {
160160
}
161161

162162
func (s *Service) loadSchemaFromFile(filename string) (*graphql.Schema, error) {
163-
definitions, err := readDefinitionFromFile(filepath.Join(s.appCfg.WatchedDir, filename))
163+
definitions, err := readDefinitionFromFile(filepath.Join(s.appCfg.OpenApiDefinitionsPath, filename))
164164
if err != nil {
165165
return nil, err
166166
}
@@ -215,7 +215,7 @@ func (s *Service) ServeHTTP(w http.ResponseWriter, r *http.Request) {
215215
return
216216
}
217217

218-
if s.appCfg.EnableKCP {
218+
if s.appCfg.EnableKcp {
219219
r = r.WithContext(kontext.WithCluster(r.Context(), logicalcluster.Name(workspace)))
220220
}
221221

listener/flags/operator_flags.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,16 @@ import (
55
)
66

77
type Flags struct {
8-
MetricsAddr string `envconfig:"default=0,optional"`
9-
EnableLeaderElection bool `envconfig:"default=false,optional"`
10-
ProbeAddr string `envconfig:"default=:8081,optional"`
11-
SecureMetrics bool `envconfig:"default=true,optional"`
12-
EnableHTTP2 bool `envconfig:"default=false,optional"`
13-
OpenAPIdefinitionsPath string `envconfig:"OPEN_API_DEFINITIONS_PATH,default=./bin/definitions"`
8+
// common with gateway
9+
OpenApiDefinitionsPath string `envconfig:"default=./bin/definitions"`
1410
EnableKcp bool `envconfig:"default=true,optional"`
11+
12+
// for listener
13+
MetricsAddr string `envconfig:"default=0,optional"`
14+
EnableLeaderElection bool `envconfig:"default=false,optional"`
15+
ProbeAddr string `envconfig:"default=:8081,optional"`
16+
SecureMetrics bool `envconfig:"default=true,optional"`
17+
EnableHTTP2 bool `envconfig:"default=false,optional"`
1518
}
1619

1720
func NewFromEnv() (*Flags, error) {

tests/service_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ func (suite *CommonTestSuite) TestWorkspaceRemove() {
146146
require.NoError(suite.T(), err)
147147
require.Equal(suite.T(), http.StatusOK, statusCode, "Expected status code 200")
148148

149-
err = os.Remove(filepath.Join(suite.appCfg.WatchedDir, workspaceName))
149+
err = os.Remove(filepath.Join(suite.appCfg.OpenApiDefinitionsPath, workspaceName))
150150
require.NoError(suite.T(), err)
151151

152152
// Wait until the handler is removed
@@ -169,7 +169,7 @@ func (suite *CommonTestSuite) TestWorkspaceRename() {
169169
require.Equal(suite.T(), http.StatusOK, statusCode, "Expected status code 200")
170170

171171
newWorkspaceName := "myNewWorkspace"
172-
err = os.Rename(filepath.Join(suite.appCfg.WatchedDir, workspaceName), filepath.Join(suite.appCfg.WatchedDir, newWorkspaceName))
172+
err = os.Rename(filepath.Join(suite.appCfg.OpenApiDefinitionsPath, workspaceName), filepath.Join(suite.appCfg.OpenApiDefinitionsPath, newWorkspaceName))
173173
require.NoError(suite.T(), err)
174174
time.Sleep(sleepTime) // let's give some time to the manager to process the file and create a url
175175

tests/suite_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ func (suite *CommonTestSuite) SetupTest() {
4040
suite.cfg, err = suite.testEnv.Start()
4141
require.NoError(suite.T(), err)
4242

43-
suite.appCfg.WatchedDir, err = os.MkdirTemp("", "watchedDir")
43+
suite.appCfg.OpenApiDefinitionsPath, err = os.MkdirTemp("", "watchedDir")
4444
require.NoError(suite.T(), err)
4545

4646
logCfg := logger.DefaultConfig()
@@ -55,14 +55,14 @@ func (suite *CommonTestSuite) SetupTest() {
5555
}
5656

5757
func (suite *CommonTestSuite) TearDownTest() {
58-
require.NoError(suite.T(), os.RemoveAll(suite.appCfg.WatchedDir))
58+
require.NoError(suite.T(), os.RemoveAll(suite.appCfg.OpenApiDefinitionsPath))
5959
require.NoError(suite.T(), suite.testEnv.Stop())
6060
suite.server.Close()
6161
}
6262

6363
// writeToFile adds a new file to the watched directory which will trigger schema generation
6464
func (suite *CommonTestSuite) writeToFile(sourceName, dest string) {
65-
specFilePath := filepath.Join(suite.appCfg.WatchedDir, dest)
65+
specFilePath := filepath.Join(suite.appCfg.OpenApiDefinitionsPath, dest)
6666

6767
sourceSpecFilePath := filepath.Join("testdata", sourceName)
6868

0 commit comments

Comments
 (0)