apisix-ingress-controller
apisix-ingress-controller copied to clipboard
request help: on crd controller: error no kind is registered for the type v2beta3.ApisixRoute in scheme
Issue description
I must first declare that I'm very new to writing operators :-).
I installed the latest apisix-ingress-controller (1.4) in my cluster. Beside for #851, all crds are looking fine:
> kubectl api-resources --api-group=apisix.apache.org (base) ⎈ (k3d-lab/kubebuilder)
NAME SHORTNAMES APIVERSION NAMESPACED KIND
apisixclusterconfigs acc apisix.apache.org/v2beta3 false ApisixClusterConfig
apisixconsumers ac apisix.apache.org/v2beta3 true ApisixConsumer
apisixpluginconfigs apc apisix.apache.org/v2beta3 true ApisixPluginConfig
apisixroutes ar apisix.apache.org/v2beta3 true ApisixRoute
apisixtlses atls apisix.apache.org/v2beta3 true ApisixTls
apisixupstreams au apisix.apache.org/v2beta3 true ApisixUpstream
I then wrote a controller that in its reconciling method creates an ApisixRoute.
import (
apisixv2beta3 "github.com/apache/apisix-ingress-controller/pkg/kube/apisix/apis/config/v2beta3"
// ... others
)
// ..
ingressRoute := &apisixv2beta3.ApisixRoute{
TypeMeta: metav1.TypeMeta{APIVersion: "v2beta3", Kind: "ApisixRoute"},
ObjectMeta: metav1.ObjectMeta{
Name: dapp.Name,
Namespace: dapp.Namespace,
Labels: map[string]string{"dapp": dapp.Name, "author": dapp.Labels["author"]},
},
Spec: apisixv2beta3.ApisixRouteSpec{
HTTP: []apisixv2beta3.ApisixRouteHTTP{
{
Name: dapp.Name,
Match: apisixv2beta3.ApisixRouteHTTPMatch{
Hosts: []string{dapp.Name + ".local"},
Paths: []string{"/"},
},
Backends: []apisixv2beta3.ApisixRouteHTTPBackend{
{
ServiceName: dapp.Name,
ServicePort: intstr.FromInt(8080),
},
},
},
},
},
}
fmt.Printf("\n\n====\n\ningressRoute: %v\n====\n\n", ingressRoute)
the trouble is,
====
ingressRoute: &{{ApisixRoute v2beta3} {my-shiny-app apisix 0 0001-01-01 00:00:00 +0000 UTC <nil> <nil> map[author:me dapp:my-shiny-app] map[] [] [] []} {[{my-shiny-app 0 <nil> {[/] [] [my-shiny-app.local] [] []} [{my-shiny-app {0 8080 } <nil> }] false [] {false {}}}] []} {[]}}
====
sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).Start.func2.2
/home/stupoh/go/pkg/mod/sigs.k8s.io/[email protected]/pkg/internal/controller/controller.go:227
1.643631557216485e+09 ERROR controller.dapp Reconciler error {"reconciler group": "bidics.mydomain", "reconciler kind": "Dapp", "name": "my-shiny-app", "namespace": "kubebuilder",
"error": "no kind is registered for the type v2beta3.ApisixRoute in scheme \"pkg/runtime/scheme.go:100\""}
sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).processNextWorkItem
/home/stupoh/go/pkg/mod/sigs.k8s.io/[email protected]/pkg/internal/controller/controller.go:266
so, no kind is registered for the type v2beta3.ApisixRoute
. My understanding is that kubectl api-resources
output can be read as there is indeed a v2beta3.ApisixRoute registered.
What did I miss? TIA
EDIT: output of printf(object)
Environment
- your apisix-ingress-controller version (output of apisix-ingress-controller version --long): 1.4
- your Kubernetes cluster version (output of kubectl version): v1.21.7+k3s1
i missed adding it to scheme :speak_no_evil:
// main.go
func init() {
apisixv2beta3.AddToScheme(scheme)
}
Updated controller that works:
ingressRoute := &apisixv2beta3.ApisixRoute{
TypeMeta: metav1.TypeMeta{APIVersion: apisixv2beta3.SchemeGroupVersion.String(), Kind: "ApisixRoute"},
ObjectMeta: metav1.ObjectMeta{
Name: dapp.Name,
Namespace: dapp.Namespace,
Labels: map[string]string{"dapp": dapp.Name, "author": dapp.Labels["author"]},
},
Spec: apisixv2beta3.ApisixRouteSpec{
HTTP: []apisixv2beta3.ApisixRouteHTTP{
{
Name: dapp.Name,
Match: apisixv2beta3.ApisixRouteHTTPMatch{
Hosts: []string{dapp.Name + ".local"},
Paths: []string{"/"},
},
Authentication: apisixv2beta3.ApisixRouteAuthentication{
Enable: false,
Type: "keyAuth",
KeyAuth: apisixv2beta3.ApisixRouteAuthenticationKeyAuth{
Header: "",
},
},
Backends: []apisixv2beta3.ApisixRouteHTTPBackend{
{
ServiceName: dapp.Name,
ServicePort: intstr.FromInt(8080),
},
},
},
},
},
}
Though Authentication
is mandatory even when the spec isn't marked so.
If my Reconciler Create()
-d the resource using
Authentication: apisixv2beta3.ApisixRouteAuthentication{
Enable: true,
Type: "keyAuth",
KeyAuth: apisixv2beta3.ApisixRouteAuthenticationKeyAuth{
Header: "XX",
},
},
the resulting k describe ar my-shiny-app
said:
Http:
Authentication:
Enable: true
Type: keyAuth
Note missing AuthKey
field there. Though with the equivalen cli, kubectl appy -f my-shiny-app-route.yaml
,
# my-shiny-app-route.yaml
authentication:
type: keyAuth
enable: true
keyAuth:
header: "XX"
will result in
Http:
Authentication:
Enable: true
Key Auth:
Header: XX
Type: keyAuth
Another one is Reconciler Patch()
will failed on default Authentication
value with message failed to create typed patch object: .spec.http[0].authentication.keyauth: field not declared in schema"
. The same error if i changed my-shiny-app-route.yaml
key of keyAuth
to keyauth
. So, Create()
succeed because it ignore Authentication
field?
What are your installation steps?
my installation from #851, using helm 0.9 on k3s 1.21
@apit Did you try this way https://github.com/apache/apisix-ingress-controller/issues/851#issuecomment-1026306420
i did. still "failed to create typed patch object: .spec.http[0].authentication.keyauth: field not declared in schema". wasnt it because of json tag of ApisixRouteAuthentication.KeyAuth?
Thanks for report. Let me check it.
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.
This issue has been closed due to lack of activity. If you think that is incorrect, or the issue requires additional review, you can revive the issue at any time.