Skip to content

Commit 5cc9ca2

Browse files
fix: docker IP handling and use repo Dockerfile (#62)
* fix: docker IP handling * feat: use Dockerfile * feat: release v0.0.10
1 parent 7589128 commit 5cc9ca2

File tree

6 files changed

+25
-12
lines changed

6 files changed

+25
-12
lines changed

Dockerfile

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
FROM alpine:3.21.3@sha256:a8560b36e8b8210634f77d9f7f9efd7ffa463e380b75e2e74aff4511df3ef88c
2+
ARG TARGETOS
3+
ARG TARGETARCH
4+
ARG COMPONENT
5+
WORKDIR /
6+
COPY bin/$COMPONENT.$TARGETOS-$TARGETARCH /<component>
7+
RUN apk add --no-cache docker-cli kind
8+
USER 65532:65532
9+
10+
# docker doesn't substitue args in ENTRYPOINT, so we replace this during the build script
11+
ENTRYPOINT ["/<component>"]

Taskfile.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ includes:
1212
COMPONENTS: 'cluster-provider-kind'
1313
REPO_URL: 'https://github.com/openmcp-project/cluster-provider-kind'
1414
CHART_COMPONENTS: "[]"
15+
DOCKERFILE: '{{.ROOT_DIR}}/Dockerfile'

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
v0.0.9-dev
1+
v0.0.10

internal/controller/accessrequest_controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ func (r *AccessRequestReconciler) handleCreateOrUpdate(ctx context.Context, ar *
102102
}
103103

104104
name := kindName(cluster)
105-
kubeconfigStr, err := r.Provider.KubeConfig(name)
105+
kubeconfigStr, err := r.Provider.KubeConfig(name, false)
106106
if err != nil {
107107
return ctrl.Result{}, err
108108
}

internal/controller/cluster_controller.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package controller
1919
import (
2020
"context"
2121
"fmt"
22+
"os"
2223

2324
apierrors "k8s.io/apimachinery/pkg/api/errors"
2425
"k8s.io/apimachinery/pkg/api/meta"
@@ -151,7 +152,7 @@ func (r *ClusterReconciler) handleCreateOrUpdate(ctx context.Context, cluster *c
151152
Reason: "ClusterExists",
152153
})
153154

154-
kubeconfig, err := r.Provider.KubeConfig(name)
155+
kubeconfig, err := r.Provider.KubeConfig(name, runsOnLocalHost())
155156
if err != nil {
156157
return requeue.Error(err)
157158
}
@@ -238,3 +239,8 @@ func namespaceOrDefault(namespace string) string {
238239
func isClusterProviderResponsible(cluster *clustersv1alpha1.Cluster) bool {
239240
return cluster.Spec.Profile == profileKind
240241
}
242+
243+
// runsOnLocalHost returns true if the KIND_ON_LOCAL_HOST environment variable is set to "true".
244+
func runsOnLocalHost() bool {
245+
return os.Getenv("KIND_ON_LOCAL_HOST") == "true"
246+
}

pkg/kind/provider.go

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ type Provider interface {
2424
// ClusterExists checks if a Kubernetes cluster with the given name exists.
2525
ClusterExists(name string) (bool, error)
2626

27-
// KubeConfig retrieves the kubeconfig for the specified cluster name.
28-
KubeConfig(name string) (string, error)
27+
// KubeConfig retrieves the kubeconfig for the specified cluster name. The bool localhosts indicates whether the function returns a kubeconfig with the local host IP or the container IP.
28+
KubeConfig(name string, localhost bool) (string, error)
2929
}
3030

3131
var (
@@ -73,8 +73,8 @@ func (p *kindProvider) DeleteCluster(name string) error {
7373
}
7474

7575
// KubeConfig implements Provider.
76-
func (p *kindProvider) KubeConfig(name string) (string, error) {
77-
kubeconfigStr, err := p.internal.KubeConfig(name, !runsOnLocalHost())
76+
func (p *kindProvider) KubeConfig(name string, localhost bool) (string, error) {
77+
kubeconfigStr, err := p.internal.KubeConfig(name, !localhost)
7878
if err != nil {
7979
return "", err
8080
}
@@ -89,11 +89,6 @@ func (p *kindProvider) KubeConfig(name string) (string, error) {
8989
return strings.ReplaceAll(kubeconfigStr, "https://"+containerName, "https://"+containerIP.String()), nil
9090
}
9191

92-
// runsOnLocalHost returns true if the KIND_ON_LOCAL_HOST environment variable is set to "true".
93-
func runsOnLocalHost() bool {
94-
return os.Getenv("KIND_ON_LOCAL_HOST") == "true"
95-
}
96-
9792
func (p *kindProvider) controlPlaneContainer(name string) string {
9893
return fmt.Sprintf("%s-control-plane", name)
9994
}

0 commit comments

Comments
 (0)