-1

I'm trying to add a conditional in my Makefile to check to see if minikube ia already running, and it if is, run a target in that same Makefile. However, it appears something is wrong with how I've written the findstring argument. Here's a snippet of my code:

Makefile Conditional Logic

So when I run this in CLI: make reset-environment

Here's the output I get back, with a few comments inserted by me with the <-- arrows:

minikube type: Control Plane host: Running kubelet: Running apiserver: Running kubeconfig: Configured <-- line 48 from my code
kubeconfig <-- line 49 from my code
ifeq (kubeconfig) <-- line 50 from my code
/bin/bash: -c: line 1: syntax error near unexpected token `kubeconfig'
/bin/bash: -c: line 1: `ifeq (kubeconfig)'
make: *** [Makefile:50: reset-environment] Error 2

According to the documentation, I have the findstring part coded correctly, which appears to be validated by the output I'm getting from link 49. But I don't understand the errors I'm hitting with line 50, and beyond.

I'm tried using different strings check for equality, and tried rewriting line 50 a few different ways, but no joy.

I also tried changing line 50 to:

ifeq ($(findstring kubeconfig,$(minikube_status)),kubeconfig)

... but that just gave me slightly different errors:

ifeq (kubeconfig,kubeconfig)
/bin/bash: -c: line 1: syntax error near unexpected token `kubeconfig,kubeconfig'
/bin/bash: -c: line 1: `ifeq (kubeconfig,kubeconfig)'
make: *** [Makefile:50: reset-environment] Error 2
  • Please don't post links to other sites, or post screenshots, in SO questions. Edit the question and cut and paste the text into the question, formatted as a code block. – MadScientist Jul 07 '23 at 18:11

1 Answers1

0

Turns out that the issue was all related to the indentation, which I saw from one of the related questions after I posted this: https://stackoverflow.com/a/4483467/22191886

I unindented those lines and sure enough, it works as designed. It just looks a little janky, but I'll survive.

  • If it "looks a little janky" it's probably because you're not fully understanding what is happening here. The indented content of the recipe is _sent to a shell to run_ when the target is parsed. That's why you got this error, because when you indented it, you sent these make commands to the shell and the shell can't parse make commands. The un-indented lines are parsed when the makefile is read in, before it runs the recipe. In this specific situation it works the same either way, but it's not really "correct" and that's why it seems janky. – MadScientist Jul 07 '23 at 18:06