Skip to content

Commit 84c2a22

Browse files
committed
start wiring in host Alliases
1 parent f130e25 commit 84c2a22

16 files changed

Lines changed: 221 additions & 61 deletions

File tree

backend/options/oidc.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,15 @@ import (
2626
"github.com/kube-bind/kube-bind/backend/oidc"
2727
)
2828

29+
type OIDCType string
30+
31+
const (
32+
OIDCTypeEmbedded OIDCType = "embedded"
33+
OIDCTypeExternal OIDCType = "external"
34+
)
35+
2936
type OIDC struct {
37+
Type string
3038
IssuerClientID string
3139
IssuerClientSecret string
3240
IssuerURL string
@@ -50,17 +58,18 @@ func (options *OIDC) AddFlags(fs *pflag.FlagSet) {
5058
fs.StringVar(&options.CallbackURL, "oidc-callback-url", options.CallbackURL, "OpenID callback URL")
5159
fs.StringVar(&options.AuthorizeURL, "oidc-authorize-url", options.AuthorizeURL, "OpenID authorize URL")
5260
fs.StringVar(&options.CAFile, "oidc-ca-file", options.CAFile, "Path to a CA bundle to use when verifying the OIDC provider's TLS certificate.")
61+
fs.StringVar(&options.Type, "oidc-type", string(options.Type), "Type of OIDC provider (embedded or external)")
5362
}
5463

5564
func (options *OIDC) Complete(listener net.Listener) error {
56-
if options.IssuerURL == "" {
65+
if options.Type == "" || options.Type == string(OIDCTypeEmbedded) {
5766
oidcServer, err := oidc.New(options.CAFile, listener)
5867
if err != nil {
5968
return err
6069
}
6170
options.OIDCServer = oidcServer
6271

63-
cfg, err := oidcServer.Config()
72+
cfg, err := oidcServer.Config(options.CallbackURL, options.IssuerURL)
6473
if err != nil {
6574
return err
6675
}

cli/go.mod

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ replace (
1010
require (
1111
github.com/MakeNowJust/heredoc v1.0.0
1212
github.com/blang/semver/v4 v4.0.0
13-
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc
13+
github.com/docker/docker v28.5.2+incompatible
1414
github.com/fatih/color v1.18.0
1515
github.com/kube-bind/kube-bind v0.0.0-00010101000000-000000000000
1616
github.com/kube-bind/kube-bind/sdk v0.4.1
@@ -41,6 +41,7 @@ require (
4141
github.com/Masterminds/semver/v3 v3.4.0 // indirect
4242
github.com/Masterminds/sprig/v3 v3.3.0 // indirect
4343
github.com/Masterminds/squirrel v1.5.4 // indirect
44+
github.com/Microsoft/go-winio v0.6.2 // indirect
4445
github.com/NYTimes/gziphandler v1.1.1 // indirect
4546
github.com/antlr4-go/antlr/v4 v4.13.1 // indirect
4647
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 // indirect
@@ -50,11 +51,16 @@ require (
5051
github.com/chai2010/gettext-go v1.0.2 // indirect
5152
github.com/containerd/containerd v1.7.28 // indirect
5253
github.com/containerd/errdefs v0.3.0 // indirect
54+
github.com/containerd/errdefs/pkg v0.3.0 // indirect
5355
github.com/containerd/log v0.1.0 // indirect
5456
github.com/containerd/platforms v0.2.1 // indirect
5557
github.com/coreos/go-semver v0.3.1 // indirect
5658
github.com/coreos/go-systemd/v22 v22.5.0 // indirect
5759
github.com/cyphar/filepath-securejoin v0.4.1 // indirect
60+
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
61+
github.com/distribution/reference v0.6.0 // indirect
62+
github.com/docker/go-connections v0.6.0 // indirect
63+
github.com/docker/go-units v0.5.0 // indirect
5864
github.com/emicklei/go-restful/v3 v3.12.2 // indirect
5965
github.com/evanphx/json-patch v5.9.11+incompatible // indirect
6066
github.com/evanphx/json-patch/v5 v5.9.11 // indirect
@@ -102,11 +108,14 @@ require (
102108
github.com/mitchellh/copystructure v1.2.0 // indirect
103109
github.com/mitchellh/go-wordwrap v1.0.1 // indirect
104110
github.com/mitchellh/reflectwalk v1.0.2 // indirect
111+
github.com/moby/docker-image-spec v1.3.1 // indirect
105112
github.com/moby/spdystream v0.5.0 // indirect
113+
github.com/moby/sys/atomicwriter v0.1.0 // indirect
106114
github.com/moby/term v0.5.2 // indirect
107115
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
108116
github.com/modern-go/reflect2 v1.0.3-0.20250322232337-35a7c28c31ee // indirect
109117
github.com/monochromegane/go-gitignore v0.0.0-20200626010858-205db1a8cc00 // indirect
118+
github.com/morikuni/aec v1.0.0 // indirect
110119
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
111120
github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f // indirect
112121
github.com/onsi/gomega v1.36.2 // indirect
@@ -163,6 +172,7 @@ require (
163172
gopkg.in/evanphx/json-patch.v4 v4.12.0 // indirect
164173
gopkg.in/inf.v0 v0.9.1 // indirect
165174
gopkg.in/yaml.v3 v3.0.1 // indirect
175+
gotest.tools/v3 v3.5.2 // indirect
166176
k8s.io/apiserver v0.34.0 // indirect
167177
k8s.io/kube-openapi v0.0.0-20250710124328-f3f2b991d03b // indirect
168178
k8s.io/kubectl v0.34.0 // indirect

cli/go.sum

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ github.com/Masterminds/sprig/v3 v3.3.0 h1:mQh0Yrg1XPo6vjYXgtf5OtijNAKJRNcTdOOGZe
2424
github.com/Masterminds/sprig/v3 v3.3.0/go.mod h1:Zy1iXRYNqNLUolqCpL4uhk6SHUMAOSCzdgBfDb35Lz0=
2525
github.com/Masterminds/squirrel v1.5.4 h1:uUcX/aBc8O7Fg9kaISIUsHXdKuqehiXAMQTYX8afzqM=
2626
github.com/Masterminds/squirrel v1.5.4/go.mod h1:NNaOrjSoIDfDA40n7sr2tPNZRfjzjA400rg+riTZj10=
27+
github.com/Microsoft/go-winio v0.6.2 h1:F2VQgta7ecxGYO8k3ZZz3RS8fVIXVxONVUPlNERoyfY=
28+
github.com/Microsoft/go-winio v0.6.2/go.mod h1:yd8OoFMLzJbo9gZq8j5qaps8bJ9aShtEA8Ipt1oGCvU=
2729
github.com/NYTimes/gziphandler v1.1.1 h1:ZUDjpQae29j0ryrS0u/B8HZfJBtBQHjqw2rQ2cqUQ3I=
2830
github.com/NYTimes/gziphandler v1.1.1/go.mod h1:n/CVRwUEOgIxrgPvAQhUUr9oeUtvrhMomdKFjzJNB0c=
2931
github.com/antlr4-go/antlr/v4 v4.13.1 h1:SqQKkuVZ+zWkMMNkjy5FZe5mr5WURWnlpmOuzYWrPrQ=
@@ -48,6 +50,8 @@ github.com/containerd/containerd v1.7.28 h1:Nsgm1AtcmEh4AHAJ4gGlNSaKgXiNccU270Dn
4850
github.com/containerd/containerd v1.7.28/go.mod h1:azUkWcOvHrWvaiUjSQH0fjzuHIwSPg1WL5PshGP4Szs=
4951
github.com/containerd/errdefs v0.3.0 h1:FSZgGOeK4yuT/+DnF07/Olde/q4KBoMsaamhXxIMDp4=
5052
github.com/containerd/errdefs v0.3.0/go.mod h1:+YBYIdtsnF4Iw6nWZhJcqGSg/dwvV7tyJ/kCkyJ2k+M=
53+
github.com/containerd/errdefs/pkg v0.3.0 h1:9IKJ06FvyNlexW690DXuQNx2KA2cUJXx151Xdx3ZPPE=
54+
github.com/containerd/errdefs/pkg v0.3.0/go.mod h1:NJw6s9HwNuRhnjJhM7pylWwMyAkmCQvQ4GpJHEqRLVk=
5155
github.com/containerd/log v0.1.0 h1:TCJt7ioM2cr/tfR8GPbGf9/VRAX8D2B4PjzCpfX540I=
5256
github.com/containerd/log v0.1.0/go.mod h1:VRRf09a7mHDIRezVKTRCrOq78v577GXq3bSa3EhrzVo=
5357
github.com/containerd/platforms v0.2.1 h1:zvwtM3rz2YHPQsF2CHYM8+KtB5dvhISiXh5ZpSBQv6A=
@@ -73,12 +77,18 @@ github.com/distribution/reference v0.6.0 h1:0IXCQ5g4/QMHHkarYzh5l+u8T3t73zM5Qvfr
7377
github.com/distribution/reference v0.6.0/go.mod h1:BbU0aIcezP1/5jX/8MP0YiH4SdvB5Y4f/wlDRiLyi3E=
7478
github.com/dlclark/regexp2 v1.11.0 h1:G/nrcoOa7ZXlpoa/91N3X7mM3r8eIlMBBJZvsz/mxKI=
7579
github.com/dlclark/regexp2 v1.11.0/go.mod h1:DHkYz0B9wPfa6wondMfaivmHpzrQ3v9q8cnmRbL6yW8=
80+
github.com/docker/docker v28.5.2+incompatible h1:DBX0Y0zAjZbSrm1uzOkdr1onVghKaftjlSWt4AFexzM=
81+
github.com/docker/docker v28.5.2+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk=
7682
github.com/docker/docker-credential-helpers v0.8.2 h1:bX3YxiGzFP5sOXWc3bTPEXdEaZSeVMrFgOr3T+zrFAo=
7783
github.com/docker/docker-credential-helpers v0.8.2/go.mod h1:P3ci7E3lwkZg6XiHdRKft1KckHiO9a2rNtyFbZ/ry9M=
84+
github.com/docker/go-connections v0.6.0 h1:LlMG9azAe1TqfR7sO+NJttz1gy6KO7VJBh+pMmjSD94=
85+
github.com/docker/go-connections v0.6.0/go.mod h1:AahvXYshr6JgfUJGdDCs2b5EZG/vmaMAntpSFH5BFKE=
7886
github.com/docker/go-events v0.0.0-20190806004212-e31b211e4f1c h1:+pKlWGMw7gf6bQ+oDZB4KHQFypsfjYlq/C4rfL7D3g8=
7987
github.com/docker/go-events v0.0.0-20190806004212-e31b211e4f1c/go.mod h1:Uw6UezgYA44ePAFQYUehOuCzmy5zmg/+nl2ZfMWGkpA=
8088
github.com/docker/go-metrics v0.0.1 h1:AgB/0SvBxihN0X8OR4SjsblXkbMvalQ8cjmtKQ2rQV8=
8189
github.com/docker/go-metrics v0.0.1/go.mod h1:cG1hvH2utMXtqgqqYE9plW6lDxS3/5ayHzueweSI3Vw=
90+
github.com/docker/go-units v0.5.0 h1:69rxXcBk27SvSaaxTtLh/8llcHD8vYHT7WSdRZ/jvr4=
91+
github.com/docker/go-units v0.5.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk=
8292
github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=
8393
github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto=
8494
github.com/emicklei/go-restful/v3 v3.12.2 h1:DhwDP0vY3k8ZzE0RunuJy8GhNpPL6zqLkDf9B/a0/xU=
@@ -223,8 +233,14 @@ github.com/mitchellh/go-wordwrap v1.0.1 h1:TLuKupo69TCn6TQSyGxwI1EblZZEsQ0vMlAFQ
223233
github.com/mitchellh/go-wordwrap v1.0.1/go.mod h1:R62XHJLzvMFRBbcrT7m7WgmE1eOyTSsCt+hzestvNj0=
224234
github.com/mitchellh/reflectwalk v1.0.2 h1:G2LzWKi524PWgd3mLHV8Y5k7s6XUvT0Gef6zxSIeXaQ=
225235
github.com/mitchellh/reflectwalk v1.0.2/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw=
236+
github.com/moby/docker-image-spec v1.3.1 h1:jMKff3w6PgbfSa69GfNg+zN/XLhfXJGnEx3Nl2EsFP0=
237+
github.com/moby/docker-image-spec v1.3.1/go.mod h1:eKmb5VW8vQEh/BAr2yvVNvuiJuY6UIocYsFu/DxxRpo=
226238
github.com/moby/spdystream v0.5.0 h1:7r0J1Si3QO/kjRitvSLVVFUjxMEb/YLj6S9FF62JBCU=
227239
github.com/moby/spdystream v0.5.0/go.mod h1:xBAYlnt/ay+11ShkdFKNAG7LsyK/tmNBVvVOwrfMgdI=
240+
github.com/moby/sys/atomicwriter v0.1.0 h1:kw5D/EqkBwsBFi0ss9v1VG3wIkVhzGvLklJ+w3A14Sw=
241+
github.com/moby/sys/atomicwriter v0.1.0/go.mod h1:Ul8oqv2ZMNHOceF643P6FKPXeCmYtlQMvpizfsSoaWs=
242+
github.com/moby/sys/sequential v0.6.0 h1:qrx7XFUd/5DxtqcoH1h438hF5TmOvzC/lspjy7zgvCU=
243+
github.com/moby/sys/sequential v0.6.0/go.mod h1:uyv8EUTrca5PnDsdMGXhZe6CCe8U/UiTWd+lL+7b/Ko=
228244
github.com/moby/term v0.5.2 h1:6qk3FJAFDs6i/q3W/pQ97SX192qKfZgGjCQqfCJkgzQ=
229245
github.com/moby/term v0.5.2/go.mod h1:d3djjFCrjnB+fl8NJux+EJzu0msscUP+f8it8hPkFLc=
230246
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
@@ -235,6 +251,8 @@ github.com/modern-go/reflect2 v1.0.3-0.20250322232337-35a7c28c31ee h1:W5t00kpgFd
235251
github.com/modern-go/reflect2 v1.0.3-0.20250322232337-35a7c28c31ee/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
236252
github.com/monochromegane/go-gitignore v0.0.0-20200626010858-205db1a8cc00 h1:n6/2gBQ3RWajuToeY6ZtZTIKv2v7ThUy5KKusIT0yc0=
237253
github.com/monochromegane/go-gitignore v0.0.0-20200626010858-205db1a8cc00/go.mod h1:Pm3mSP3c5uWn86xMLZ5Sa7JB9GsEZySvHYXCTK4E9q4=
254+
github.com/morikuni/aec v1.0.0 h1:nP9CBfwrvYnBRgY6qfDQkygYDmYwOilePFkwzv4dU8A=
255+
github.com/morikuni/aec v1.0.0/go.mod h1:BbKIizmSmc5MMPqRYbxO4ZU0S0+P200+tUnFx7PXmsc=
238256
github.com/muesli/reflow v0.3.0 h1:IFsN6K9NfGtjeggFP+68I4chLZV2yIKsXJFNZ+eWh6s=
239257
github.com/muesli/reflow v0.3.0/go.mod h1:pbwTDkVPibjO2kyvBQRBxTWEEGDGq0FlB1BIKtnHY/8=
240258
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA=
@@ -474,6 +492,8 @@ gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
474492
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
475493
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
476494
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
495+
gotest.tools/v3 v3.5.2 h1:7koQfIKdy+I8UTetycgUqXWSDwpgv193Ka+qRsmBY8Q=
496+
gotest.tools/v3 v3.5.2/go.mod h1:LtdLGcnqToBH83WByAAi/wiwSFCArdFIUV/xxN4pcjA=
477497
helm.sh/helm/v3 v3.19.0 h1:krVyCGa8fa/wzTZgqw0DUiXuRT5BPdeqE/sQXujQ22k=
478498
helm.sh/helm/v3 v3.19.0/go.mod h1:Lk/SfzN0w3a3C3o+TdAKrLwJ0wcZ//t1/SDXAvfgDdc=
479499
k8s.io/api v0.34.0 h1:L+JtP2wDbEYPUeNGbeSa/5GwFtIA662EmT2YSLOkAVE=

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

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,15 @@ type BindAPIServiceOptions struct {
6060
SkipKonnector bool
6161
KonnectorImageOverride string
6262
DowngradeKonnector bool
63-
NoBanner bool
64-
DryRun bool
65-
Template string
66-
Name string
63+
// KonnectorHostAlias is a list of host alias entries to add to the konnector pods.
64+
KonnectorHostAlias []string
65+
// parsed KonnectorHostAlias entries
66+
konnectorHostAlias []corev1.HostAlias
67+
68+
NoBanner bool
69+
DryRun bool
70+
Template string
71+
Name string
6772
}
6873

6974
// NewBindAPIServiceOptions returns new BindAPIServiceOptions.
@@ -95,6 +100,8 @@ func (b *BindAPIServiceOptions) AddCmdFlags(cmd *cobra.Command) {
95100
cmd.Flags().MarkHidden("konnector-image") //nolint:errcheck
96101
cmd.Flags().BoolVar(&b.NoBanner, "no-banner", b.NoBanner, "Do not show the red banner")
97102
cmd.Flags().MarkHidden("no-banner") //nolint:errcheck
103+
cmd.Flags().StringSliceVarP(&b.KonnectorHostAlias, "konnector-host-alias", "", []string{}, "Add a host alias to the konnector pods in the format IP:hostname1,hostname2")
104+
cmd.Flags().MarkHidden("konnector-host-alias") //nolint:errcheck
98105
}
99106

100107
// Complete ensures all fields are initialized.
@@ -112,6 +119,16 @@ func (b *BindAPIServiceOptions) Complete(args []string) error {
112119
}
113120

114121
b.printer = printer
122+
123+
// parse konnector host alias entries
124+
for _, hostAlias := range b.KonnectorHostAlias {
125+
parts := strings.SplitN(hostAlias, ":", 2)
126+
hostnames := strings.Split(parts[1], ",")
127+
b.konnectorHostAlias = append(b.konnectorHostAlias, corev1.HostAlias{
128+
IP: parts[0],
129+
Hostnames: hostnames,
130+
})
131+
}
115132
return nil
116133
}
117134

@@ -139,6 +156,19 @@ func (b *BindAPIServiceOptions) Validate() error {
139156
return errors.New("name is required")
140157
}
141158

159+
for _, hostAlias := range b.KonnectorHostAlias {
160+
parts := strings.SplitN(hostAlias, ":", 2)
161+
if len(parts) != 2 {
162+
return fmt.Errorf("invalid konnector-host-alias entry %q, expected format IP:hostname1,hostname2", hostAlias)
163+
}
164+
if parts[0] == "" {
165+
return fmt.Errorf("invalid konnector-host-alias entry %q, IP address is empty", hostAlias)
166+
}
167+
if parts[1] == "" {
168+
return fmt.Errorf("invalid konnector-host-alias entry %q, hostnames are empty", hostAlias)
169+
}
170+
}
171+
142172
return b.Options.Validate()
143173
}
144174

@@ -156,6 +186,7 @@ func (b *BindAPIServiceOptions) Run(ctx context.Context) error {
156186
IOStreams: b.Options.IOStreams,
157187
SkipKonnector: b.SkipKonnector,
158188
KonnectorImageOverride: b.KonnectorImageOverride,
189+
KonnectorHostAlias: b.konnectorHostAlias,
159190
DowngradeKonnector: b.DowngradeKonnector,
160191
RemoteKubeconfigFile: b.remoteKubeconfigFile,
161192
RemoteKubeconfigNamespace: b.remoteKubeconfigNamespace,

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"io"
2424
"os"
2525

26+
corev1 "k8s.io/api/core/v1"
2627
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2728
"k8s.io/cli-runtime/pkg/genericclioptions"
2829
kubeclient "k8s.io/client-go/kubernetes"
@@ -38,6 +39,7 @@ type BinderOptions struct {
3839
IOStreams genericclioptions.IOStreams
3940
SkipKonnector bool
4041
KonnectorImageOverride string
42+
KonnectorHostAlias []corev1.HostAlias
4143
DowngradeKonnector bool
4244
RemoteKubeconfigFile string
4345
RemoteKubeconfigNamespace string
@@ -281,6 +283,7 @@ func (b *Binder) deployKonnector(ctx context.Context) error {
281283
KonnectorImageOverride: b.opts.KonnectorImageOverride,
282284
DowngradeKonnector: b.opts.DowngradeKonnector,
283285
DryRun: b.opts.DryRun,
286+
konnectorHostAlias: b.opts.KonnectorHostAlias,
284287
}
285288
return tempOpts.deployKonnector(ctx, b.config)
286289
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ func (b *BindAPIServiceOptions) deployKonnector(ctx context.Context, config *res
6969

7070
if b.KonnectorImageOverride != "" {
7171
fmt.Fprintf(b.Options.ErrOut, "🚀 Deploying konnector %s to namespace kube-bind with custom image %q.\n", bindVersion, b.KonnectorImageOverride)
72-
if err := konnector.Bootstrap(ctx, discoveryClient, dynamicClient, b.KonnectorImageOverride); err != nil {
72+
if err := konnector.Bootstrap(ctx, discoveryClient, dynamicClient, b.KonnectorImageOverride, b.konnectorHostAlias); err != nil {
7373
return err
7474
}
7575
} else if !b.SkipKonnector {

cli/pkg/kubectl/dev/plugin/dev.go

Lines changed: 57 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ import (
2525
"strings"
2626
"time"
2727

28+
"github.com/docker/docker/api/types/container"
29+
"github.com/docker/docker/client"
2830
"github.com/kube-bind/kube-bind/cli/pkg/kubectl/base"
2931
"github.com/spf13/cobra"
3032
"helm.sh/helm/v3/pkg/action"
@@ -100,6 +102,9 @@ func (o *DevOptions) Validate() error {
100102

101103
var providerClusterConfig = `apiVersion: kind.x-k8s.io/v1alpha4
102104
kind: Cluster
105+
networking:
106+
apiServerAddress: "0.0.0.0"
107+
apiServerPort: 6443
103108
nodes:
104109
- role: control-plane
105110
extraPortMappings:
@@ -127,6 +132,13 @@ func (o *DevOptions) Run(ctx context.Context) error {
127132
return err
128133
}
129134

135+
providerIP, err := o.getClusterIPAddress(ctx, o.ProviderClusterName, "kube-bind-dev")
136+
if err != nil {
137+
klog.FromContext(ctx).Error(err, "Failed to get provider cluster IP address")
138+
} else {
139+
klog.FromContext(ctx).Info("Provider cluster IP address", "ip", providerIP)
140+
}
141+
130142
if err := o.createCluster(ctx, o.ConsumerClusterName, consumerClusterConfig, false); err != nil {
131143
return err
132144
}
@@ -259,6 +271,43 @@ func (o *DevOptions) cleanupHostEntries(ctx context.Context) error {
259271
return nil
260272
}
261273

274+
func (o *DevOptions) getClusterIPAddress(ctx context.Context, clusterName, networkName string) (string, error) {
275+
dockerClient, err := client.NewClientWithOpts(client.FromEnv, client.WithAPIVersionNegotiation())
276+
if err != nil {
277+
return "", fmt.Errorf("failed to create docker client: %w", err)
278+
}
279+
defer dockerClient.Close()
280+
281+
// Get the container name for the kind cluster control plane
282+
containerName := fmt.Sprintf("%s-control-plane", clusterName)
283+
284+
containers, err := dockerClient.ContainerList(ctx, container.ListOptions{})
285+
if err != nil {
286+
return "", fmt.Errorf("failed to list containers: %w", err)
287+
}
288+
289+
for _, c := range containers {
290+
for _, name := range c.Names {
291+
if strings.Contains(name, containerName) {
292+
containerDetails, err := dockerClient.ContainerInspect(ctx, c.ID)
293+
if err != nil {
294+
return "", fmt.Errorf("failed to inspect container %s: %w", c.ID, err)
295+
}
296+
297+
if networks := containerDetails.NetworkSettings.Networks; networks != nil {
298+
if network, exists := networks[networkName]; exists {
299+
if network.IPAddress != "" {
300+
return network.IPAddress, nil
301+
}
302+
}
303+
}
304+
}
305+
}
306+
}
307+
308+
return "", fmt.Errorf("could not find IP address for cluster %s in network %s", clusterName, networkName)
309+
}
310+
262311
func (o *DevOptions) installHelmChart(ctx context.Context, restConfig *rest.Config) error {
263312
actionConfig := new(action.Configuration)
264313

@@ -269,17 +318,21 @@ func (o *DevOptions) installHelmChart(ctx context.Context, restConfig *rest.Conf
269318
values := map[string]interface{}{
270319
"image": map[string]interface{}{
271320
"repository": "ghcr.io/mjudeikis/backend",
272-
"tag": "2e01ef5",
321+
"tag": "f130e25",
273322
},
274323
"examples": map[string]interface{}{
275324
"enabled": true,
276325
},
277326
"backend": map[string]interface{}{
278-
"listenAddress": "0.0.0.0:8080",
279-
"namespacePrefix": "kube-bind-",
280-
"consumerScope": "cluster",
327+
"listenAddress": "0.0.0.0:8080",
328+
"namespacePrefix": "kube-bind-",
329+
"externalAddress": "https://kube-bind.dev.local:6443",
330+
"externalServerName": "kind-provider-control-plane",
331+
"consumerScope": "cluster",
281332
"oidc": map[string]interface{}{
282333
"callbackUrl": "http://kube-bind.dev.local:8080/api/callback",
334+
"issuerUrl": "http://kube-bind.dev.local:8080/oidc",
335+
"type": "embedded",
283336
},
284337
},
285338
"service": map[string]interface{}{

0 commit comments

Comments
 (0)