Default function not being executed

Hi, with the test.js file i setup a kubernetes configmap and the corresponding k6 CRD. the only thing i get when running the file is the console.log outputs before the export default fucntion but the export default function never seems to execute it always stuck on running with pod status.

import http from 'k6/http';
  import { check } from 'k6';
  console.log("test");
  export let options = {
    stages: [
      { target: 1, duration: '3s' },
      { target: 1, duration: '3s' },
    ],
  };
  console.log("test2");
  export default function () {
    console.log("made it");
    const result = http.get('https://test-api.k6.io/public/crocodiles/');
    check(result, {
      'http response status code is 200': result.status === 200,
    });
  }

The yaml file

apiVersion: k6.io/v1alpha1
kind: K6
metadata:
  name: k6-test
  namespace: k6-operator-system
spec:
  parallelism: 1
  script:
    configMap:
      name: k6test
      file: test.js

output:

time="2023-05-12T10:42:37Z" level=info msg=test source=console
time="2023-05-12T10:42:37Z" level=info msg=test2 source=console
time="2023-05-12T10:42:37Z" level=info msg=test source=console
time="2023-05-12T10:42:37Z" level=info msg=test2 source=console

Hi @Walorda

Welcome to the community forum :wave:

Did you already have a look at the operator logs? Can you share them?

Cheers!

failed to get status from <service> {"namespace": "k6-operator-system", "name": "<service>", "reconcileID": "######", "error": "Get \"http://<service>.k6-operator-system.svc.cluster.local:6565/v1/status\": dial tcp: lookup <service>.k6-operator-system.svc.cluster.local on <ip>: no such host"}

i figured out the error, we are running it on a different kubernetes domain name but i cant seem to compile the code again and fix it?

I changed the code from here

func isServiceReady(log logr.Logger, service *v1.Service) bool {
	resp, err := http.Get(fmt.Sprintf("http://%v.%v.svc.<custom domain>:6565/v1/status", service.ObjectMeta.Name, service.ObjectMeta.Namespace))

	if err != nil {
		log.Error(err, fmt.Sprintf("failed to get status from %v", service.ObjectMeta.Name))
		return false
	}

	return resp.StatusCode < 400
}

but still giving me the same error. i geuss it has to do with compiling the new code but i cant seem to figure out how to do that as its not displaying my printf(‘testlogtest’) eather in the code.

Hi @Walorda,

It looks like there’s an issue in the setup of the cluster itself. Have you tried going through Kubernetes troubleshooting guides?

/etc/resolv.conf should contain both the default domain and your custom domain.

1 Like