Skip to content

Commit 136c4ab

Browse files
authored
Adding a new Minikube flag for helm chart install of Apache Camel K (#521)
* 🎁 Adding a new flag on Minikube for helm chart install of Apache Camel K Signed-off-by: Matthias Wessendorf <[email protected]> * 💄 Applying feedbac from David S. Signed-off-by: Matthias Wessendorf <[email protected]> --------- Signed-off-by: Matthias Wessendorf <[email protected]>
1 parent 770d27b commit 136c4ab

File tree

5 files changed

+94
-3
lines changed

5 files changed

+94
-3
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
## Getting Started
88

9-
Note: In order to use the `quickstart` plugin, you must install the [Kubernetes CLI `kubectl`](https://kubernetes.io/docs/tasks/tools/install-kubectl) and either [`kind`](https://kind.sigs.k8s.io/docs/user/quick-start) or [`minikube`](https://minikube.sigs.k8s.io/docs/start/).
9+
Note: In order to use the `quickstart` plugin, you must install the [Kubernetes CLI `kubectl`](https://kubernetes.io/docs/tasks/tools/install-kubectl) and either [`kind`](https://kind.sigs.k8s.io/docs/user/quick-start) or [`minikube`](https://minikube.sigs.k8s.io/docs/start/). If you want to install the Apache Camel K option you also need the [`helm`](https://helm.sh/) CLI.
1010

1111
### Installation
1212

internal/command/flags.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ var name string
2424
var kubernetesVersion string
2525
var installServing bool
2626
var installEventing bool
27+
var installCamel bool
2728
var installKindRegistry bool
2829
var installKindExtraMountHostPath string
2930
var installKindExtraMountContainerPath string
@@ -55,6 +56,10 @@ func installEventingOption(targetCmd *cobra.Command) {
5556
targetCmd.Flags().BoolVar(&installEventing, "install-eventing", false, "install Eventing on quickstart cluster")
5657
}
5758

59+
func installCamelOption(targetCmd *cobra.Command) {
60+
targetCmd.Flags().BoolVar(&installCamel, "install-camel", false, "install Apache Camel K on quickstart cluster")
61+
}
62+
5863
func installKindRegistryOption(targetCmd *cobra.Command) {
5964
targetCmd.Flags().BoolVar(&installKindRegistry, "registry", false, "install registry for Kind quickstart cluster")
6065
}

internal/command/minikube.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,14 @@ func NewMinikubeCommand() *cobra.Command {
3030
Short: "Quickstart with Minikube",
3131
RunE: func(cmd *cobra.Command, args []string) error {
3232
fmt.Println("Running Knative Quickstart using Minikube")
33-
return minikube.SetUp(name, kubernetesVersion, installServing, installEventing)
33+
return minikube.SetUp(name, kubernetesVersion, installServing, installEventing, installCamel)
3434
},
3535
}
3636
// Set minikubeCmd options
3737
clusterNameOption(minikubeCmd, "knative")
3838
kubernetesVersionOption(minikubeCmd, "", "kubernetes version to use (1.x.y)")
3939
installServingOption(minikubeCmd)
4040
installEventingOption(minikubeCmd)
41+
installCamelOption(minikubeCmd)
4142
return minikubeCmd
4243
}

pkg/install/install.go

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,34 @@ metadata:
205205
return nil
206206
}
207207

208+
func CamelK(registryAddress string) error {
209+
fmt.Println("🐪 Installing Apache Camel K ... ")
210+
211+
if err := addHelmRepo(); err != nil {
212+
fmt.Printf("Error adding Helm repo: %v\n", err)
213+
return err
214+
}
215+
fmt.Println("Helm repo added successfully")
216+
217+
// Run the Helm install command
218+
if err := runHelmInstall(registryAddress); err != nil {
219+
fmt.Printf("Error: %v\n", err)
220+
return err
221+
}
222+
223+
if err := waitForCRDsEstablished(); err != nil {
224+
return fmt.Errorf("crds: %w", err)
225+
}
226+
fmt.Println(" CRDs installed...")
227+
228+
if err := waitForPodsReady("default"); err != nil {
229+
return fmt.Errorf("core: %w", err)
230+
}
231+
fmt.Println(" Apache Camel K installed...")
232+
233+
return nil
234+
}
235+
208236
func runCommand(c *exec.Cmd) error {
209237
if out, err := c.CombinedOutput(); err != nil {
210238
fmt.Println(string(out))
@@ -237,3 +265,37 @@ func waitForCRDsEstablished() error {
237265
func waitForPodsReady(ns string) error {
238266
return runCommand(exec.Command("kubectl", "wait", "pod", "--timeout=10m", "--for=condition=Ready", "-l", "!job-name", "-n", ns))
239267
}
268+
269+
//nolint:gosec // avoid linter warnings
270+
func runHelmInstall(registryAddress string) error {
271+
272+
// Check if helm CLI is installed
273+
if _, err := exec.LookPath("helm"); err != nil {
274+
return fmt.Errorf("Please install helm CLI")
275+
}
276+
277+
cmd := exec.Command("helm", "install",
278+
"--generate-name",
279+
"--set", fmt.Sprintf("platform.build.registry.address=%s", registryAddress),
280+
"--set", "platform.build.registry.insecure=true",
281+
"camel-k/camel-k")
282+
283+
cmd.Stdout = cmd.Stderr
284+
285+
if out, err := cmd.CombinedOutput(); err != nil {
286+
fmt.Println(string(out))
287+
return fmt.Errorf("failed to run helm install: %w", err)
288+
}
289+
return nil
290+
}
291+
292+
func addHelmRepo() error {
293+
cmd := exec.Command("helm", "repo", "add", "camel-k", "https://apache.github.io/camel-k/charts/")
294+
cmd.Stdout = cmd.Stderr
295+
296+
if out, err := cmd.CombinedOutput(); err != nil {
297+
fmt.Println(string(out))
298+
return fmt.Errorf("failed to add helm repo: %w", err)
299+
}
300+
return nil
301+
}

pkg/minikube/minikube.go

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ var memory = "3072"
3535
var installKnative = true
3636

3737
// SetUp creates a local Minikube cluster and installs all the relevant Knative components
38-
func SetUp(name, kVersion string, installServing, installEventing bool) error {
38+
func SetUp(name, kVersion string, installServing, installEventing, installCamel bool) error {
3939
start := time.Now()
4040

4141
// if neither the "install-serving" or "install-eventing" flags are set,
@@ -83,6 +83,19 @@ func SetUp(name, kVersion string, installServing, installEventing bool) error {
8383
if err := install.Eventing(); err != nil {
8484
return fmt.Errorf("install eventing: %w", err)
8585
}
86+
87+
if installCamel {
88+
89+
registryAddress, err := getMinikubeRegistryAddress()
90+
if err != nil {
91+
fmt.Printf("Error: %v\n", err)
92+
return err
93+
}
94+
95+
if err := install.CamelK(registryAddress); err != nil {
96+
return fmt.Errorf("install Apache Camel K: %w", err)
97+
}
98+
}
8699
}
87100
}
88101

@@ -271,3 +284,13 @@ func recreateCluster() error {
271284
}
272285
return nil
273286
}
287+
288+
func getMinikubeRegistryAddress() (string, error) {
289+
cmd := exec.Command("kubectl", "-n", "kube-system", "get", "service", "registry", "-o", "jsonpath={.spec.clusterIP}")
290+
out, err := cmd.CombinedOutput()
291+
if err != nil {
292+
return "", fmt.Errorf("failed to get registry address: %w", err)
293+
}
294+
address := strings.TrimSpace(string(out))
295+
return address, nil
296+
}

0 commit comments

Comments
 (0)