Skip to content

Commit 258ed1f

Browse files
authored
Merge pull request #18 from faroshq/grab.a.bag.part2
version fallback
2 parents 5c4b341 + 648a4e2 commit 258ed1f

4 files changed

Lines changed: 41 additions & 12 deletions

File tree

deploy/charts/kedge-agent/templates/deployment.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ spec:
2323
imagePullSecrets:
2424
{{- toYaml . | nindent 8 }}
2525
{{- end }}
26+
{{- with .Values.hostAliases }}
27+
hostAliases:
28+
{{- toYaml . | nindent 8 }}
29+
{{- end }}
2630
serviceAccountName: {{ include "kedge-agent.serviceAccountName" . }}
2731
securityContext:
2832
{{- toYaml .Values.podSecurityContext | nindent 8 }}
@@ -38,6 +42,9 @@ spec:
3842
{{- if .Values.agent.hub.context }}
3943
- --hub-context={{ .Values.agent.hub.context }}
4044
{{- end }}
45+
{{- if .Values.agent.hub.url }}
46+
- --hub-url={{ .Values.agent.hub.url }}
47+
{{- end }}
4148
{{- if .Values.agent.tunnelURL }}
4249
- --tunnel-url={{ .Values.agent.tunnelURL }}
4350
{{- end }}

deploy/charts/kedge-agent/values.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ agent:
2626
kubeconfig: ""
2727
# -- Optional: kubeconfig context to use
2828
context: ""
29+
# -- Optional: override hub URL (useful for dev environments where the
30+
# kubeconfig server URL differs from the actual reachable URL)
31+
url: ""
2932

3033
# -- Optional: separate tunnel URL (defaults to hub URL from kubeconfig)
3134
tunnelURL: ""
@@ -56,6 +59,14 @@ nodeSelector: {}
5659
tolerations: []
5760
affinity: {}
5861
podAnnotations: {}
62+
63+
# -- Host aliases to add to the pod (useful for dev environments)
64+
# Example:
65+
# hostAliases:
66+
# - ip: "172.18.0.2"
67+
# hostnames:
68+
# - "kedge.localhost"
69+
hostAliases: []
5970
podSecurityContext:
6071
fsGroup: 65534
6172
securityContext:

pkg/agent/agent.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,10 @@ func New(opts *Options) (*Agent, error) {
8181
if err != nil {
8282
return nil, fmt.Errorf("failed to build hub config from kubeconfig: %w", err)
8383
}
84+
// Allow HubURL to override the kubeconfig's server URL (useful for dev environments)
85+
if opts.HubURL != "" {
86+
hubConfig.Host = opts.HubURL
87+
}
8488
} else if opts.HubURL != "" {
8589
hubConfig = &rest.Config{
8690
Host: opts.HubURL,

pkg/cli/cmd/dev/plugin/create.go

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,13 @@ type DevOptions struct {
6161
AgentClusterName string
6262
WaitForReadyTimeout time.Duration
6363
ChartPath string
64+
AgentChartPath string
6465
ChartVersion string
6566
KindNetwork string
6667
}
6768

6869
// fallbackAssetVersion is used when unable to fetch the latest version
69-
const fallbackAssetVersion = "0.1.0"
70+
const fallbackAssetVersion = "0.0.1"
7071

7172
// gitHubRelease represents a GitHub release response
7273
type gitHubRelease struct {
@@ -80,6 +81,7 @@ func NewDevOptions(streams genericclioptions.IOStreams) *DevOptions {
8081
HubClusterName: "kedge-hub",
8182
AgentClusterName: "kedge-agent",
8283
ChartPath: "deploy/charts/kedge-hub",
84+
AgentChartPath: "oci://ghcr.io/faroshq/charts/kedge-agent",
8385
ChartVersion: fallbackAssetVersion,
8486
}
8587
}
@@ -89,7 +91,8 @@ func (o *DevOptions) AddCmdFlags(cmd *cobra.Command) {
8991
cmd.Flags().StringVar(&o.HubClusterName, "hub-cluster-name", "kedge-hub", "Name of the hub cluster in dev mode")
9092
cmd.Flags().StringVar(&o.AgentClusterName, "agent-cluster-name", "kedge-agent", "Name of the agent cluster in dev mode")
9193
cmd.Flags().DurationVar(&o.WaitForReadyTimeout, "wait-for-ready-timeout", 2*time.Minute, "Timeout for waiting for the cluster to be ready")
92-
cmd.Flags().StringVar(&o.ChartPath, "chart-path", o.ChartPath, "Helm chart path or OCI registry URL")
94+
cmd.Flags().StringVar(&o.ChartPath, "chart-path", o.ChartPath, "Helm chart path or OCI registry URL for hub")
95+
cmd.Flags().StringVar(&o.AgentChartPath, "agent-chart-path", o.AgentChartPath, "Helm chart path or OCI registry URL for agent")
9396
cmd.Flags().StringVar(&o.ChartVersion, "chart-version", o.ChartVersion, "Helm chart version")
9497
cmd.Flags().StringVar(&o.Image, "image", "ghcr.io/faroshq/kedge-hub", "kedge hub image to use in dev mode")
9598
cmd.Flags().StringVar(&o.Tag, "tag", "", "kedge hub image tag to use in dev mode")
@@ -127,7 +130,7 @@ func fetchLatestRelease() (string, error) {
127130
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
128131
defer cancel()
129132

130-
req, err := http.NewRequestWithContext(ctx, http.MethodGet, "https://api.github.com/repos/faroshq/faros-kedge/releases/latest", nil)
133+
req, err := http.NewRequestWithContext(ctx, http.MethodGet, "https://api.github.com/repos/faroshq/kedge/releases/latest", nil)
131134
if err != nil {
132135
return "", fmt.Errorf("failed to create request: %w", err)
133136
}
@@ -185,9 +188,6 @@ nodes:
185188

186189
var agentClusterConfig = `apiVersion: kind.x-k8s.io/v1alpha4
187190
kind: Cluster
188-
networking:
189-
apiServerAddress: "0.0.0.0"
190-
apiServerPort: 6443
191191
nodes:
192192
- role: control-plane
193193
`
@@ -279,13 +279,20 @@ func (o *DevOptions) runWithColors(ctx context.Context) error {
279279
o.AgentClusterName, o.AgentClusterName)))
280280

281281
_, _ = fmt.Fprint(o.Streams.ErrOut, " Then install the agent Helm chart:\n")
282-
_, _ = fmt.Fprintf(o.Streams.ErrOut, "%s\n\n", blueCommand(fmt.Sprintf(
283-
"helm install kedge-agent deploy/charts/kedge-agent \\\n --kubeconfig %s.kubeconfig \\\n -n kedge-system \\\n --set agent.siteName=my-site \\\n --set agent.hub.existingSecret=site-kubeconfig",
284-
o.AgentClusterName)))
285-
286282
if hubIP != "" {
287-
_, _ = fmt.Fprint(o.Streams.ErrOut, " Note: The agent connects to the hub via the Docker network.\n")
288-
_, _ = fmt.Fprintf(o.Streams.ErrOut, " Hub is reachable at: https://%s:8443 from within the kind network.\n\n", hubIP)
283+
// Use hub.url to override the kubeconfig server URL with the correct NodePort address
284+
// The kubeconfig has kedge.localhost:8443 which works from host, but from within
285+
// the Docker network we need to use the hub's IP and NodePort 31443
286+
_, _ = fmt.Fprintf(o.Streams.ErrOut, "%s\n\n", blueCommand(fmt.Sprintf(
287+
"helm install kedge-agent %s --version %s \\\n --kubeconfig %s.kubeconfig \\\n -n kedge-system \\\n --set agent.siteName=my-site \\\n --set agent.hub.existingSecret=site-kubeconfig \\\n --set agent.hub.url=https://%s:31443",
288+
o.AgentChartPath, o.ChartVersion, o.AgentClusterName, hubIP)))
289+
} else {
290+
_, _ = fmt.Fprintf(o.Streams.ErrOut, "%s\n\n", blueCommand(fmt.Sprintf(
291+
"helm install kedge-agent %s --version %s \\\n --kubeconfig %s.kubeconfig \\\n -n kedge-system \\\n --set agent.siteName=my-site \\\n --set agent.hub.existingSecret=site-kubeconfig",
292+
o.AgentChartPath, o.ChartVersion, o.AgentClusterName)))
293+
_, _ = fmt.Fprint(o.Streams.ErrOut, " Note: You may need to set agent.hub.url to the hub's Docker network IP and NodePort.\n")
294+
_, _ = fmt.Fprint(o.Streams.ErrOut, " Get hub IP: docker inspect kedge-hub-control-plane | jq -r '.[0].NetworkSettings.Networks[\"kedge-dev\"].IPAddress'\n")
295+
_, _ = fmt.Fprint(o.Streams.ErrOut, " Then add: --set agent.hub.url=https://<HUB_IP>:31443\n\n")
289296
}
290297

291298
_, _ = fmt.Fprint(o.Streams.ErrOut, "Useful commands:\n")

0 commit comments

Comments
 (0)