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

Forward-port changes from 4.1.1 #380

Merged
merged 12 commits into from
Dec 19, 2018
12 changes: 10 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,15 @@ Kubeclient release versioning follows [SemVer](https://semver.org/).
- Really made `Kubeclient::Config.new(data, nil)` prevent external file lookups.
README documented this since 3.1.1 (#334) but alas that was a lie — absolute paths always worked.

## 4.1.0 — 2018-11-28
## 4.1.1 — 2018-12-17

### Fixed

- Fixed method names for non-suffix plurals such as y -> ies (#377).

## 4.1.0 — 2018-11-28 — REGRESSION

This version broke method names where plural is not just adding a suffix, notably y -> ies (bug #376).

### Fixed
- Support custom resources with lowercase `kind` (#361).
Expand Down Expand Up @@ -39,7 +47,7 @@ Kubeclient release versioning follows [SemVer](https://semver.org/).

## 3.1.1 - 2018-06-01 — REGRESSION

In this version `Kubeclient::Config.read` raises Psych::DisallowedClass on legal yaml configs containing a timestamp, for example gcp access-token expiry (#337).
In this version `Kubeclient::Config.read` raises Psych::DisallowedClass on legal yaml configs containing a timestamp, for example gcp access-token expiry (bug #337).

### Security
- Changed `Kubeclient::Config.read` to use `YAML.safe_load` (#334).
Expand Down
36 changes: 24 additions & 12 deletions lib/kubeclient/common.rb
Original file line number Diff line number Diff line change
Expand Up @@ -132,13 +132,13 @@ def discover
end

def self.parse_definition(kind, name)
# Kubernetes gives us have 3 inputs:
# kind: "ComponentStatus"
# name: "componentstatuses"
# singularName: "componentstatus" (usually kind.downcase)
# Kubernetes gives us 3 inputs:
# kind: "ComponentStatus", "NetworkPolicy", "Endpoints"
# name: "componentstatuses", "networkpolicies", "endpoints"
# singularName: "componentstatus" etc (usually omitted, defaults to kind.downcase)
# and want to derive singular and plural method names, with underscores:
# "component_status"
# "component_statuses"
# "network_policy"
# "network_policies"
# kind's CamelCase word boundaries determine our placement of underscores.

if IRREGULAR_NAMES[kind]
Expand All @@ -150,13 +150,22 @@ def self.parse_definition(kind, name)
# But how? If it differs from kind.downcase, kind's word boundaries don't apply.
singular_name = kind.downcase

if name.start_with?(kind.downcase)
plural_suffix = name[kind.downcase.length..-1] # "es"
singular_underscores = ClientMixin.underscore_entity(kind) # "component_status"
method_names = [singular_underscores, singular_underscores + plural_suffix]
else
# Something weird, can't infer underscores for plural so just give them up
if !(/[A-Z]/ =~ kind)
# Some custom resources have a fully lowercase kind - can't infer underscores.
method_names = [singular_name, name]
else
# Some plurals are not exact suffixes, e.g. NetworkPolicy -> networkpolicies.
# So don't expect full last word to match.
/^(?<prefix>(.*[A-Z]))(?<singular_suffix>[^A-Z]*)$/ =~ kind # "NetworkP", "olicy"
if name.start_with?(prefix.downcase)
plural_suffix = name[prefix.length..-1] # "olicies"
prefix_underscores = ClientMixin.underscore_entity(prefix) # "network_p"
method_names = [prefix_underscores + singular_suffix, # "network_policy"
prefix_underscores + plural_suffix] # "network_policies"
else
# Something weird, can't infer underscores for plural so just give them up
method_names = [singular_name, name]
end
end
end

Expand Down Expand Up @@ -507,6 +516,9 @@ def load_entities
@entities = {}
fetch_entities['resources'].each do |resource|
next if resource['name'].include?('/')
# Not a regular entity, special functionality covered by `process_template`.
# https://github.com/openshift/origin/issues/21668
next if resource['kind'] == 'Template' && resource['name'] == 'processedtemplates'
resource['kind'] ||=
Kubeclient::Common::MissingKindCompatibility.resource_kind(resource['name'])
entity = ClientMixin.parse_definition(resource['kind'], resource['name'])
Expand Down
2 changes: 1 addition & 1 deletion lib/kubeclient/version.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Kubernetes REST-API Client
module Kubeclient
VERSION = '4.1.0'.freeze
VERSION = '4.1.1'.freeze
end
217 changes: 217 additions & 0 deletions test/json/extensions_v1beta1_api_resource_list.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,217 @@
{
"kind": "APIResourceList",
"groupVersion": "extensions/v1beta1",
"resources": [
{
"name": "daemonsets",
"singularName": "",
"namespaced": true,
"kind": "DaemonSet",
"verbs": [
"create",
"delete",
"deletecollection",
"get",
"list",
"patch",
"update",
"watch"
],
"shortNames": [
"ds"
]
},
{
"name": "daemonsets/status",
"singularName": "",
"namespaced": true,
"kind": "DaemonSet",
"verbs": [
"get",
"patch",
"update"
]
},
{
"name": "deployments",
"singularName": "",
"namespaced": true,
"kind": "Deployment",
"verbs": [
"create",
"delete",
"deletecollection",
"get",
"list",
"patch",
"update",
"watch"
],
"shortNames": [
"deploy"
]
},
{
"name": "deployments/rollback",
"singularName": "",
"namespaced": true,
"kind": "DeploymentRollback",
"verbs": [
"create"
]
},
{
"name": "deployments/scale",
"singularName": "",
"namespaced": true,
"group": "extensions",
"version": "v1beta1",
"kind": "Scale",
"verbs": [
"get",
"patch",
"update"
]
},
{
"name": "deployments/status",
"singularName": "",
"namespaced": true,
"kind": "Deployment",
"verbs": [
"get",
"patch",
"update"
]
},
{
"name": "ingresses",
"singularName": "",
"namespaced": true,
"kind": "Ingress",
"verbs": [
"create",
"delete",
"deletecollection",
"get",
"list",
"patch",
"update",
"watch"
],
"shortNames": [
"ing"
]
},
{
"name": "ingresses/status",
"singularName": "",
"namespaced": true,
"kind": "Ingress",
"verbs": [
"get",
"patch",
"update"
]
},
{
"name": "networkpolicies",
"singularName": "",
"namespaced": true,
"kind": "NetworkPolicy",
"verbs": [
"create",
"delete",
"deletecollection",
"get",
"list",
"patch",
"update",
"watch"
],
"shortNames": [
"netpol"
]
},
{
"name": "podsecuritypolicies",
"singularName": "",
"namespaced": false,
"kind": "PodSecurityPolicy",
"verbs": [
"create",
"delete",
"deletecollection",
"get",
"list",
"patch",
"update",
"watch"
],
"shortNames": [
"psp"
]
},
{
"name": "replicasets",
"singularName": "",
"namespaced": true,
"kind": "ReplicaSet",
"verbs": [
"create",
"delete",
"deletecollection",
"get",
"list",
"patch",
"update",
"watch"
],
"shortNames": [
"rs"
]
},
{
"name": "replicasets/scale",
"singularName": "",
"namespaced": true,
"group": "extensions",
"version": "v1beta1",
"kind": "Scale",
"verbs": [
"get",
"patch",
"update"
]
},
{
"name": "replicasets/status",
"singularName": "",
"namespaced": true,
"kind": "ReplicaSet",
"verbs": [
"get",
"patch",
"update"
]
},
{
"name": "replicationcontrollers",
"singularName": "",
"namespaced": true,
"kind": "ReplicationControllerDummy",
"verbs": []
},
{
"name": "replicationcontrollers/scale",
"singularName": "",
"namespaced": true,
"kind": "Scale",
"verbs": [
"get",
"patch",
"update"
]
}
]
}
27 changes: 27 additions & 0 deletions test/json/template.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"apiVersion": "template.openshift.io/v1",
"kind": "Template",
"metadata": {
"creationTimestamp": "2018-12-17T16:11:36Z",
"name": "my-template",
"namespace": "default",
"resourceVersion": "21954",
"selfLink": "/apis/template.openshift.io/v1/namespaces/default/templates/my-template",
"uid": "6e03e3e6-0216-11e9-b1e0-68f728fac3ab"
},
"objects": [
{
"apiVersion": "v1",
"kind": "Service",
"metadata": {
"name": "${NAME_PREFIX}my-service"
}
}
],
"parameters": [
{
"description": "Prefix for names",
"name": "NAME_PREFIX"
}
]
}
Loading