Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

custom resources & istio #360

Closed
f4tq opened this issue Nov 5, 2018 · 3 comments · Fixed by #370
Closed

custom resources & istio #360

f4tq opened this issue Nov 5, 2018 · 3 comments · Fixed by #370

Comments

@f4tq
Copy link

f4tq commented Nov 5, 2018

Hi,
First off, many thanks for kubeclient. It works very well.

I've been able to - mostly - use kubeclient to discover and instantiate all istio objects via kubeclient but there are a couple exceptions.

The istio 1.0.3 custom resource definitions in question raise an exception due to the kind for a bunch of their definitions not having a capital letter in kind - rbac.istio.io and configs.istio.io.
I'm able fix it like this by just using kind in lib/kubeclient/common.rb:

-      prefix = kind[0..kind.rindex(/[A-Z]/)] # NetworkP
+      prefix = kind =~ /[A-Z]/ ? kind[0..kind.rindex(/[A-Z]/)] : kind # NetworkP

I'll submit a PR for this if you'd like but given that some of the generated functions might not follow your pattern, I thought I'd ask first. I also see that you have a istio fork so you may have seen this already. Please advise.

Here is how I'm instantiating the client to the using the api group/version form:

  istioRbacClient = Kubeclient::Client.new(
    "#{context.api_endpoint}/apis/rbac.istio.io",
    "v1alpha1" ,
    ssl_options: context.ssl_options,
    auth_options: context.auth_options
  )

AND

  istioConfigClient = Kubeclient::Client.new(
    "#{context.api_endpoint}/apis/config.istio.io",
    "v1alpha2" ,
    ssl_options: context.ssl_options,
    auth_options: context.auth_options
  ) 

The exception before the change above looks like :

Resource: https://XXXXX.hcp.eastus2.azmk8s.io/apis/config.istio.io/v1alpha2
parse_definition kind noop name: noops
Couldn't read /output/packages/kubeconfig.json ["/var/lib/gems/2.3.0/gems/kubeclient-4.0.0/lib/kubeclient/common.rb:136:in `parse_definition'", "/var/lib/gems/2.3.0/gems/kubeclient-4.0.0/lib/kubeclient/common.rb:481:in `block in load_entities'", "/var/lib/gems/2.3.0/gems/kubeclient-4.0.0/lib/kubeclient/
common.rb:477:in `each'", "/var/lib/gems/2.3.0/gems/kubeclient-4.0.0/lib/kubeclient/common.rb:477:in `load_entities'", "/var/lib/gems/2.3.0/gems/kubeclient-4.0.0/lib/kubeclient/common.rb:123:in `discover'", "scripts/onboard.rb:156:in `<main>'"] bad value for range

After the above fix, and with some added puts' to show the method definition i get

Resource: https://signb-test-signtestue21cb38-1cb380-dfb53596.hcp.eastus2.azmk8s.io/apis/config.istio.io/v1alpha2
parse_definition kind HTTPAPISpecBinding name: httpapispecbindings
parse_definition kind QuotaSpec name: quotaspecs
parse_definition kind kubernetesenv name: kubernetesenvs
parse_definition kind metric name: metrics
parse_definition kind instance name: instances
parse_definition kind denier name: deniers
parse_definition kind fluentd name: fluentds
parse_definition kind prometheus name: prometheuses
parse_definition kind stackdriver name: stackdrivers
parse_definition kind reportnothing name: reportnothings
parse_definition kind HTTPAPISpec name: httpapispecs
parse_definition kind dogstatsd name: dogstatsds
parse_definition kind edge name: edges
parse_definition kind servicecontrolreport name: servicecontrolreports
parse_definition kind handler name: handlers
parse_definition kind attributemanifest name: attributemanifests
parse_definition kind rbac name: rbacs
parse_definition kind redisquota name: redisquotas
parse_definition kind signalfx name: signalfxs
parse_definition kind listentry name: listentries
parse_definition kind noop name: noops
parse_definition kind servicecontrol name: servicecontrols
parse_definition kind solarwinds name: solarwindses
parse_definition kind stdio name: stdios
parse_definition kind checknothing name: checknothings
parse_definition kind QuotaSpecBinding name: quotaspecbindings
parse_definition kind circonus name: circonuses
parse_definition kind listchecker name: listcheckers
parse_definition kind opa name: opas
parse_definition kind apikey name: apikeys
parse_definition kind tracespan name: tracespans
parse_definition kind bypass name: bypasses
parse_definition kind cloudwatch name: cloudwatches
parse_definition kind statsd name: statsds
parse_definition kind authorization name: authorizations
parse_definition kind quota name: quotas
parse_definition kind template name: templates
parse_definition kind rule name: rules
parse_definition kind memquota name: memquotas
parse_definition kind kubernetes name: kuberneteses
parse_definition kind logentry name: logentries
parse_definition kind adapter name: adapters
define_entity_methods: httpapispec_bindings httpapispec_binding
define_entity_methods: quota_specs quota_spec
define_entity_methods: kubernetesenvs kubernetesenv
define_entity_methods: metrics metric
define_entity_methods: instances instance
define_entity_methods: deniers denier
define_entity_methods: fluentds fluentd
define_entity_methods: prometheuses prometheus
define_entity_methods: stackdrivers stackdriver
define_entity_methods: reportnothings reportnothing
define_entity_methods: httpapispecs httpapispec
define_entity_methods: dogstatsds dogstatsd
define_entity_methods: edges edge
define_entity_methods: servicecontrolreports servicecontrolreport
define_entity_methods: handlers handler
define_entity_methods: attributemanifests attributemanifest
define_entity_methods: rbacs rbac
define_entity_methods: redisquotas redisquota
define_entity_methods: signalfxs signalfx
define_entity_methods: noops noop
define_entity_methods: servicecontrols servicecontrol
define_entity_methods: solarwindses solarwinds
define_entity_methods: stdios stdio
define_entity_methods: checknothings checknothing
define_entity_methods: quota_spec_bindings quota_spec_binding
define_entity_methods: circonuses circonus
define_entity_methods: listcheckers listchecker
define_entity_methods: opas opa
define_entity_methods: apikeys apikey
define_entity_methods: tracespans tracespan
define_entity_methods: bypasses bypass
define_entity_methods: cloudwatches cloudwatch
define_entity_methods: statsds statsd
define_entity_methods: authorizations authorization
define_entity_methods: quotas quota
define_entity_methods: templates template
define_entity_methods: rules rule
define_entity_methods: memquotas memquota
define_entity_methods: kuberneteses kubernetes
define_entity_methods: adapters adapter

Thanks,
Chris

@cben
Copy link
Collaborator

cben commented Nov 5, 2018

Ooh, interesting corner case! Custom resources are great for stressing kubeclient :-)
Can you try with new implementation of lowercasing from #355?

@f4tq
Copy link
Author

f4tq commented Nov 5, 2018

No, that doesn't work. From the looks of it, the spec in PR 355 needs some lower case kinds.
I think a PR for this is in order as it won't collide with 355.
FTR, here is the kubectl api-resources. Notice all the lower-case 'kind's.

root@vagrant:/work/src/git.corp.adobe.com/adobe-platform/dcos-azure# kubectl api-resources | grep istio
NAME                              SHORTNAMES   APIGROUP                       NAMESPACED   KIND
meshpolicies                                   authentication.istio.io        false        MeshPolicy
policies                                       authentication.istio.io        true         Policy
adapters                                       config.istio.io                true         adapter
apikeys                                        config.istio.io                true         apikey
attributemanifests                             config.istio.io                true         attributemanifest
authorizations                                 config.istio.io                true         authorization
bypasses                                       config.istio.io                true         bypass
checknothings                                  config.istio.io                true         checknothing
circonuses                                     config.istio.io                true         circonus
cloudwatches                                   config.istio.io                true         cloudwatch
deniers                                        config.istio.io                true         denier
dogstatsds                                     config.istio.io                true         dogstatsd
edges                                          config.istio.io                true         edge
fluentds                                       config.istio.io                true         fluentd
handlers                                       config.istio.io                true         handler
httpapispecbindings                            config.istio.io                true         HTTPAPISpecBinding
httpapispecs                                   config.istio.io                true         HTTPAPISpec
instances                                      config.istio.io                true         instance
kubernetesenvs                                 config.istio.io                true         kubernetesenv
kuberneteses                                   config.istio.io                true         kubernetes
listcheckers                                   config.istio.io                true         listchecker
listentries                                    config.istio.io                true         listentry
logentries                                     config.istio.io                true         logentry
memquotas                                      config.istio.io                true         memquota
metrics                                        config.istio.io                true         metric
noops                                          config.istio.io                true         noop
opas                                           config.istio.io                true         opa
prometheuses                                   config.istio.io                true         prometheus
quotas                                         config.istio.io                true         quota
quotaspecbindings                              config.istio.io                true         QuotaSpecBinding
quotaspecs                                     config.istio.io                true         QuotaSpec
rbacs                                          config.istio.io                true         rbac
redisquotas                                    config.istio.io                true         redisquota
reportnothings                                 config.istio.io                true         reportnothing
rules                                          config.istio.io                true         rule
servicecontrolreports                          config.istio.io                true         servicecontrolreport
servicecontrols                                config.istio.io                true         servicecontrol
signalfxs                                      config.istio.io                true         signalfx
solarwindses                                   config.istio.io                true         solarwinds
stackdrivers                                   config.istio.io                true         stackdriver
statsds                                        config.istio.io                true         statsd
stdios                                         config.istio.io                true         stdio
templates                                      config.istio.io                true         template
tracespans                                     config.istio.io                true         tracespan
destinationrules                               networking.istio.io            true         DestinationRule
envoyfilters                                   networking.istio.io            true         EnvoyFilter
gateways                                       networking.istio.io            true         Gateway
serviceentries                                 networking.istio.io            true         ServiceEntry
virtualservices                                networking.istio.io            true         VirtualService
rbacconfigs                                    rbac.istio.io                  true         RbacConfig
servicerolebindings                            rbac.istio.io                  true         ServiceRoleBinding
serviceroles                                   rbac.istio.io                  true         ServiceRole

@cben
Copy link
Collaborator

cben commented Nov 21, 2018

Fixed by #361.

@cben cben closed this as completed Nov 21, 2018
cben added a commit to cben/kubeclient that referenced this issue Nov 23, 2018
cben added a commit to cben/kubeclient that referenced this issue Nov 26, 2018
@cben cben mentioned this issue Nov 28, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants