Skip to content

Commit 89c2cba

Browse files
committed
address reviews
1 parent 464b9d2 commit 89c2cba

16 files changed

Lines changed: 91 additions & 120 deletions

File tree

.github/workflows/image.yaml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,6 @@ jobs:
2222
go-version: v1.24.0
2323
check-latest: true
2424

25-
- name: Set up Node.js
26-
uses: actions/setup-node@v4
27-
with:
28-
node-version: '20'
29-
cache: 'npm'
30-
cache-dependency-path: web/package-lock.json
31-
3225
# We need this to remove local tags that are not semver so goreleaser doesn't get confused.
3326
- name: Delete non-semver tags
3427
run: 'git tag -d $(git tag -l | grep -v "^v")'

Dockerfile.konnector

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2022 The Kube Bind Authors.
1+
# Copyright 2025 The Kube Bind Authors.
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.

backend/auth/handler.go

Lines changed: 33 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -184,45 +184,47 @@ func (ah *AuthHandler) HandleCallback(w http.ResponseWriter, r *http.Request) {
184184
parsedRedirectURL.RawQuery = values.Encode()
185185

186186
http.Redirect(w, r, parsedRedirectURL.String(), http.StatusFound)
187-
} else {
188-
// UI flow - set cookie and redirect to UI
189-
cookieName := ah.generateCookieName(authCode.ClusterID)
190-
s := securecookie.New(ah.cookieSigningKey, ah.cookieEncryptionKey)
191-
encoded, err := s.Encode(cookieName, sessionState)
192-
if err != nil {
193-
logger.Error(err, "failed to encode secure session cookie")
194-
http.Error(w, "internal error", http.StatusInternalServerError)
195-
return
196-
}
187+
return
188+
}
197189

198-
secure := false
199-
http.SetCookie(w, session.MakeCookie(r, cookieName, encoded, secure, 1*time.Hour))
190+
// UI flow - set cookie and redirect to UI
191+
cookieName := ah.generateCookieName(authCode.ClusterID)
192+
s := securecookie.New(ah.cookieSigningKey, ah.cookieEncryptionKey)
193+
encoded, err := s.Encode(cookieName, sessionState)
194+
if err != nil {
195+
logger.Error(err, "failed to encode secure session cookie")
196+
http.Error(w, "internal error", http.StatusInternalServerError)
197+
return
198+
}
200199

201-
clientParams := &client.ClientParameters{
202-
ClusterID: authCode.ClusterID,
203-
ClientSideRedirectURL: authCode.ClientSideRedirectURL,
204-
RedirectURL: authCode.RedirectURL,
205-
SessionID: authCode.SessionID,
206-
}
207-
url := clientParams.WithParams(authCode.RedirectURL)
200+
secure := false
201+
http.SetCookie(w, session.MakeCookie(r, cookieName, encoded, secure, 1*time.Hour))
208202

209-
http.Redirect(w, r, url, http.StatusFound)
203+
clientParams := &client.ClientParameters{
204+
ClusterID: authCode.ClusterID,
205+
ClientSideRedirectURL: authCode.ClientSideRedirectURL,
206+
RedirectURL: authCode.RedirectURL,
207+
SessionID: authCode.SessionID,
210208
}
209+
url := clientParams.WithParams(authCode.RedirectURL)
210+
211+
http.Redirect(w, r, url, http.StatusFound)
211212
}
212213

213214
func (ah *AuthHandler) respondWithError(w http.ResponseWriter, clientType ClientType, message string, statusCode int) {
214-
if clientType == ClientTypeCLI {
215-
w.Header().Set("Content-Type", "application/json")
216-
w.WriteHeader(statusCode)
217-
err := json.NewEncoder(w).Encode(AuthResponse{
218-
Success: false,
219-
Error: message,
220-
})
221-
if err != nil {
222-
http.Error(w, "internal error", http.StatusInternalServerError)
223-
}
224-
} else {
215+
if clientType != ClientTypeCLI {
225216
http.Error(w, message, statusCode)
217+
return
218+
}
219+
220+
w.Header().Set("Content-Type", "application/json")
221+
w.WriteHeader(statusCode)
222+
err := json.NewEncoder(w).Encode(AuthResponse{
223+
Success: false,
224+
Error: message,
225+
})
226+
if err != nil {
227+
http.Error(w, "internal error", http.StatusInternalServerError)
226228
}
227229
}
228230

backend/auth/types.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ type TokenResponse struct {
4343
ClusterID string `json:"cluster_id,omitempty"`
4444
}
4545

46+
// TODO: We should remove client_side_redirect_url.
47+
// https://github.com/kube-bind/kube-bind/issues/362
48+
4649
type AuthorizeRequest struct {
4750
RedirectURL string `json:"redirect_url" form:"redirect_url"`
4851
ClientSideRedirectURL string `json:"client_side_redirect_url" form:"client_side_redirect_url"`

backend/http/handler.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,8 @@ func (h *handler) AddRoutes(mux *mux.Router) error {
130130
apiRouter.Handle("/ping", auth.RequireAuth(http.HandlerFunc(h.handlePing))).Methods(http.MethodGet)
131131

132132
switch {
133+
// Development mode: proxy to frontend dev server
133134
case strings.HasPrefix(h.frontend, "http://"):
134-
// Development mode: proxy to frontend dev server
135135
spaserver, err := spaserver.NewSPAReverseProxyServer(h.frontend)
136136
if err != nil {
137137
return err

backend/server.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,7 @@ func NewServer(ctx context.Context, c *Config) (*Server, error) {
124124
if err != nil {
125125
return nil, fmt.Errorf("error setting up HTTP Handler: %w", err)
126126
}
127-
err = handler.AddRoutes(s.WebServer.Router)
128-
if err != nil {
127+
if err := handler.AddRoutes(s.WebServer.Router); err != nil {
129128
return nil, fmt.Errorf("error adding routes to HTTP Server: %w", err)
130129
}
131130

cli/pkg/client/client.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,13 @@ import (
3434
)
3535

3636
type Client interface {
37-
GetTemplates(ctx context.Context) (*kubebindv1alpha2.APIServiceExportTemplateList, error)
38-
GetCollections(ctx context.Context) (*kubebindv1alpha2.CollectionList, error)
39-
Bind(ctx context.Context, request *kubebindv1alpha2.BindableResourcesRequest) (*kubebindv1alpha2.BindingResourceResponse, error)
37+
GetTemplates(context.Context) (*kubebindv1alpha2.APIServiceExportTemplateList, error)
38+
GetCollections(context.Context) (*kubebindv1alpha2.CollectionList, error)
39+
Bind(context.Context, *kubebindv1alpha2.BindableResourcesRequest) (*kubebindv1alpha2.BindingResourceResponse, error)
4040

41-
Get(urlStr string) (*http.Response, error)
42-
Post(urlStr string, body io.Reader) (*http.Response, error)
43-
Do(req *http.Request) (*http.Response, error)
41+
Get(string) (*http.Response, error)
42+
Post(string, io.Reader) (*http.Response, error)
43+
Do(*http.Request) (*http.Response, error)
4444
}
4545

4646
// authenticatedClient provides an HTTP client with automatic authentication
@@ -152,8 +152,8 @@ func (c *authenticatedClient) Bind(ctx context.Context, request *kubebindv1alpha
152152
}
153153

154154
// Get performs an authenticated GET request
155-
func (c *authenticatedClient) Get(urlStr string) (*http.Response, error) {
156-
req, err := http.NewRequest("GET", urlStr, nil)
155+
func (c *authenticatedClient) Get(url string) (*http.Response, error) {
156+
req, err := http.NewRequest("GET", url, nil)
157157
if err != nil {
158158
return nil, err
159159
}
@@ -166,8 +166,8 @@ func (c *authenticatedClient) Get(urlStr string) (*http.Response, error) {
166166
}
167167

168168
// Post performs an authenticated POST request
169-
func (c *authenticatedClient) Post(urlStr string, body io.Reader) (*http.Response, error) {
170-
req, err := http.NewRequest("POST", urlStr, body)
169+
func (c *authenticatedClient) Post(url string, body io.Reader) (*http.Response, error) {
170+
req, err := http.NewRequest("POST", url, body)
171171
if err != nil {
172172
return nil, err
173173
}

cli/pkg/kubectl/base/browser.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,5 @@ func isWindows() bool {
4545

4646
// isMacOS checks if the current OS is macOS
4747
func isMacOS() bool {
48-
cmd := exec.Command("uname")
49-
output, err := cmd.Output()
50-
if err != nil {
51-
return false
52-
}
53-
return strings.TrimSpace(string(output)) == "Darwin"
48+
return strings.Contains(strings.ToLower(exec.Command("uname").String()), "darwin")
5449
}

cli/pkg/kubectl/base/options.go

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@ type Options struct {
4040
Kubeconfig string
4141
// KubectlOverrides stores the extra client connection fields, such as context, user, etc.
4242
KubectlOverrides *clientcmd.ConfigOverrides
43-
// Server is the kube-bind server name to use (overrides kube-bind config current server)
44-
Server string
45-
// Cluster is the kube-bind cluster name to use (overrides kube-bind config current cluster)
46-
Cluster string
43+
// ServerName is the kube-bind server name to use (overrides kube-bind config current server)
44+
ServerName string
45+
// ClusterName is the kube-bind cluster name to use (overrides kube-bind config current cluster)
46+
ClusterName string
4747
// SkipInsecure skips TLS verification (for development)
4848
SkipInsecure bool
4949
// ConfigFile is the path to the kube-bind configuration file
@@ -87,8 +87,8 @@ func (o *Options) BindFlags(cmd *cobra.Command) {
8787
clientcmd.BindOverrideFlags(o.KubectlOverrides, cmd.PersistentFlags(), kubectlConfigOverrideFlags)
8888

8989
// Add common kube-bind flags
90-
cmd.Flags().StringVar(&o.Server, "server", o.Server, "The kube-bind server name to use (overrides kube-bind config current server)")
91-
cmd.Flags().StringVar(&o.Cluster, "cluster", o.Cluster, "The kube-bind cluster name to use (overrides kube-bind config current cluster)")
90+
cmd.Flags().StringVar(&o.ServerName, "server", o.ServerName, "The kube-bind server name to use (overrides kube-bind config current server)")
91+
cmd.Flags().StringVar(&o.ClusterName, "cluster", o.ClusterName, "The kube-bind cluster name to use (overrides kube-bind config current cluster)")
9292
cmd.Flags().BoolVar(&o.SkipInsecure, "insecure-skip-tls-verify", false, "Skip TLS certificate verification (not recommended)")
9393
cmd.Flags().StringVar(&o.ConfigFile, "config-file", "", "Path to the kube-bind configuration file")
9494
}
@@ -123,16 +123,16 @@ func (o *Options) Complete(skipValidate bool) error {
123123
}
124124

125125
switch {
126-
case o.Server != "" && o.Cluster != "":
126+
case o.ServerName != "" && o.ClusterName != "":
127127
// Both server and cluster specified separately - do nothing
128-
case o.Server != "" && strings.Contains(o.Server, "@"):
128+
case o.ServerName != "" && strings.Contains(o.ServerName, "@"):
129129
// Server specified in server@cluster format
130-
parts := strings.SplitN(o.Server, "@", 2)
131-
o.Server = parts[0]
132-
o.Cluster = parts[1]
133-
case o.Server != "" && o.Cluster == "":
130+
parts := strings.SplitN(o.ServerName, "@", 2)
131+
o.ServerName = parts[0]
132+
o.ClusterName = parts[1]
133+
case o.ServerName != "" && o.ClusterName == "":
134134
// Only server specified - do nothing. Cluster is empty
135-
case o.Server == "":
135+
case o.ServerName == "":
136136
// No server specified - do nothing. Will be resolved from config
137137
}
138138

@@ -141,7 +141,7 @@ func (o *Options) Complete(skipValidate bool) error {
141141
// So if its empty here, we need to resolve it.
142142
var s *config.Server
143143
var c *config.Config
144-
if o.Server == "" {
144+
if o.ServerName == "" {
145145
c, err = config.LoadConfigFromFile(o.ConfigFile)
146146
if err != nil {
147147
return fmt.Errorf("failed to load config: %w", err)
@@ -159,11 +159,11 @@ func (o *Options) Complete(skipValidate bool) error {
159159
}
160160

161161
var exists bool
162-
s, exists = c.Get(o.Server, o.Cluster)
162+
s, exists = c.Get(o.ServerName, o.ClusterName)
163163
if !exists && !skipValidate {
164-
err := fmt.Errorf("server %q not found in config", o.Server)
165-
if o.Cluster != "" {
166-
err = fmt.Errorf("server %q with cluster %q not found in config", o.Server, o.Cluster)
164+
err := fmt.Errorf("server %q not found in config", o.ServerName)
165+
if o.ClusterName != "" {
166+
err = fmt.Errorf("server %q with cluster %q not found in config", o.ServerName, o.ClusterName)
167167
}
168168
return err
169169
}
@@ -174,8 +174,8 @@ func (o *Options) Complete(skipValidate bool) error {
174174
}
175175

176176
if s != nil {
177-
o.Server = s.URL
178-
o.Cluster = s.Cluster
177+
o.ServerName = s.URL
178+
o.ClusterName = s.Cluster
179179
}
180180
o.server = s
181181
o.config = c
@@ -185,14 +185,14 @@ func (o *Options) Complete(skipValidate bool) error {
185185

186186
// Validate validates the configured options.
187187
func (o *Options) Validate() error {
188-
if o.Server != "" && strings.Contains(o.Server, "@") && o.Cluster != "" {
188+
if o.ServerName != "" && strings.Contains(o.ServerName, "@") && o.ClusterName != "" {
189189
return fmt.Errorf("cannot specify both server in 'server@cluster' format and --cluster flag")
190190
}
191191

192-
if o.Cluster != "" && o.Server == "" {
192+
if o.ClusterName != "" && o.ServerName == "" {
193193
return fmt.Errorf("cannot specify --cluster without --server")
194194
}
195-
if _, err := url.Parse(o.Server); err != nil {
195+
if _, err := url.Parse(o.ServerName); err != nil {
196196
return fmt.Errorf("invalid server URL: %w", err)
197197
}
198198

cli/pkg/kubectl/bind-apiservice/plugin/bind.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ func (b *BindAPIServiceOptions) AddCmdFlags(cmd *cobra.Command) {
8282
b.Print.AddFlags(cmd)
8383

8484
cmd.Flags().StringVar(&b.Template, "template-name", b.Template, "A template name to use for binding")
85+
cmd.Flags().StringVar(&b.Name, "name", b.Name, "The name of the BindableResourcesRequest to create")
8586
cmd.Flags().StringVar(&b.remoteKubeconfigFile, "remote-kubeconfig", b.remoteKubeconfigFile, "A file path for a kubeconfig file to connect to the service provider cluster")
8687
cmd.Flags().StringVar(&b.remoteKubeconfigNamespace, "remote-kubeconfig-namespace", b.remoteKubeconfigNamespace, "The namespace of the remote kubeconfig secret to read from")
8788
cmd.Flags().StringVar(&b.remoteKubeconfigName, "remote-kubeconfig-name", b.remoteKubeconfigNamespace, "The name of the remote kubeconfig secret to read from")

0 commit comments

Comments
 (0)