apisix-ingress-controller icon indicating copy to clipboard operation
apisix-ingress-controller copied to clipboard

bug: create ApisixRoute failed by k8s dynamic client-go

Open jianghushinian opened this issue 2 years ago • 6 comments

Current Behavior

func buildK8sApisixRoute(name, namespace string, port int32) *apisixv2.ApisixRoute {
	return &apisixv2.ApisixRoute{
		TypeMeta: metav1.TypeMeta{
			APIVersion: "apisix.apache.org/v2",
			Kind:       "ApisixRoute",
		},
		ObjectMeta: metav1.ObjectMeta{
			Name:      name,
			Namespace: namespace,
		},
		Spec: apisixv2.ApisixRouteSpec{
			HTTP: []apisixv2.ApisixRouteHTTP{
				{
					Name: name,
					Match: apisixv2.ApisixRouteHTTPMatch{
						Hosts: []string{"xxx"},
						Paths: []string{"/*"},
					},
					Backends: []apisixv2.ApisixRouteHTTPBackend{
						{
							ServiceName: name,
							ServicePort: intstr.IntOrString{
								Type:   intstr.Int,
								IntVal: port,
							},
						},
					},
				},
			},
		},
	}
}

Expected Behavior

success

Error Logs

ApisixRoute.apisix.apache.org "demo" is invalid: spec.http[0].authentication.type: Unsupported value: "": supported values: "basicAuth", "keyAuth", "jwtAuth", "wolfRBAC", "hmacAuth", "ldapAuth"

Steps to Reproduce

  1. create apisixroutes cr
  2. failed

Environment

  • APISIX Ingress controller version (run apisix-ingress-controller version --long)
  • Kubernetes cluster version (run kubectl version)
  • OS version if running APISIX Ingress controller in a bare-metal environment (run uname -a)

jianghushinian avatar Feb 01 '24 02:02 jianghushinian

if wrote:

func buildK8sApisixRoute(name, namespace string, port int32) *apisixv2.ApisixRoute {
	return &apisixv2.ApisixRoute{
		TypeMeta: metav1.TypeMeta{
			APIVersion: "apisix.apache.org/v2",
			Kind:       "ApisixRoute",
		},
		ObjectMeta: metav1.ObjectMeta{
			Name:      name,
			Namespace: namespace,
		},
		Spec: apisixv2.ApisixRouteSpec{
			HTTP: []apisixv2.ApisixRouteHTTP{
				{
					Name: name,
					Match: apisixv2.ApisixRouteHTTPMatch{
						Hosts: []string{"xxx"},
						Paths: []string{"/*"},
					},
					Backends: []apisixv2.ApisixRouteHTTPBackend{
						{
							ServiceName: name,
							ServicePort: intstr.IntOrString{
								Type:   intstr.Int,
								IntVal: port,
							},
						},
					},
					Authentication: apisixv2.ApisixRouteAuthentication{
						Enable: false,
						Type:   "basicAuth",
					},
				},
			},
		},
	}
}

will success.

the following code is necessary, but useless, if we should use pointers to avoid mandatory parameters?

Authentication: apisixv2.ApisixRouteAuthentication{
		Enable: false,
		Type:   "basicAuth",
	}

jianghushinian avatar Feb 01 '24 02:02 jianghushinian

There's a lot more of these that have omitempty but can can't marshall from Go as nil values. Would suggest we fix these in a big swoop (being mindful of possible NPE) since it breaks other library API consumers.

acuteaura avatar Feb 01 '24 06:02 acuteaura

@acuteaura I think the change is meaningful enough that we can introduce it even if it is breaking. Replacing these fields as pointers looks good to me. The consumers should be able to upgrade to newer version with code changes. @AlinsRan What do you think?

Revolyssup avatar Feb 01 '24 07:02 Revolyssup

This issue has been marked as stale due to 90 days of inactivity. It will be closed in 30 days if no further activity occurs. If this issue is still relevant, please simply write any comment. Even if closed, you can still revive the issue at any time or discuss it on the [email protected] list. Thank you for your contributions.

github-actions[bot] avatar May 02 '24 01:05 github-actions[bot]

@Revolyssup removing the stale label. Please check and triage.

pottekkat avatar May 02 '24 02:05 pottekkat

This issue has been marked as stale due to 90 days of inactivity. It will be closed in 30 days if no further activity occurs. If this issue is still relevant, please simply write any comment. Even if closed, you can still revive the issue at any time or discuss it on the [email protected] list. Thank you for your contributions.

github-actions[bot] avatar Aug 01 '24 01:08 github-actions[bot]