-
Notifications
You must be signed in to change notification settings - Fork 26
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
Fix Client#get_resources for custom resources that are not yet defined #14
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
457dca7
spec get_resources happy case
3bc322e
spec resource 404 handling
e9289af
spec broken crd case
bc3ce79
transport: fix gets options handling to allow skip_missing: true
ef9eb11
specs: conditional DEBUG from env
cf2cf45
Client#apis: support skip_missing: true
90eb68d
Client#get_resources: skip requests for custom resources that are not…
09be3f1
clarify comment
bfdddee
comment on CRD delete during stack prune
75041d3
fix test crd to be valid
3b0a4af
refactor using Util.compact_yield helper
9425099
rename Util.sparse_map, less argument unpacking
0b771de
compromise on compact_map, because sparse isn't ruby terminology
affa829
trivial specs for compact_map
6d2f7ae
add note on duplicate args
c35c448
abbreviate block arg to not shadow outer local
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,3 +11,4 @@ | |
require 'k8s/resource_client' | ||
require 'k8s/stack' | ||
require 'k8s/transport' | ||
require 'k8s/util' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
module K8s | ||
module Util | ||
# Yield with all non-nil args, returning matching array with corresponding return values or nils. | ||
# | ||
# Args must be usable as hash keys. Duplicate args will all map to the same return value. | ||
# | ||
# @param args [Array<nil, Object>] | ||
# @yield args | ||
# @yieldparam args [Array<Object>] omitting any nil values | ||
# @return [Array<nil, Object>] matching args array 1:1, containing yielded values for non-nil args | ||
def self.compact_map(args) | ||
func_args = args.compact | ||
|
||
values = yield func_args | ||
|
||
# Hash{arg => value} | ||
value_map = Hash[func_args.zip(values)] | ||
|
||
args.map{|arg| value_map[arg] } | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"kind": "Status", | ||
"apiVersion": "v1", | ||
"metadata": { | ||
|
||
}, | ||
"status": "Failure", | ||
"message": "configmaps \"bar\" not found", | ||
"reason": "NotFound", | ||
"details": { | ||
"name": "bar", | ||
"kind": "configmaps" | ||
}, | ||
"code": 404 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"apiVersion": "v1", | ||
"data": { | ||
"foo": "bar" | ||
}, | ||
"kind": "ConfigMap", | ||
"metadata": { | ||
"creationTimestamp": "2018-08-13T08:07:22Z", | ||
"name": "bar", | ||
"namespace": "default", | ||
"resourceVersion": "3718", | ||
"selfLink": "/api/v1/namespaces/default/configmaps/bar", | ||
"uid": "e8293208-9ecf-11e8-b464-76d458035df6" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
{ | ||
"apiVersion": "v1", | ||
"kind": "Service", | ||
"metadata": { | ||
"creationTimestamp": "2018-08-13T08:06:38Z", | ||
"name": "foo", | ||
"namespace": "default", | ||
"resourceVersion": "3646", | ||
"selfLink": "/api/v1/namespaces/default/services/foo", | ||
"uid": "cdc7144a-9ecf-11e8-b464-76d458035df6" | ||
}, | ||
"spec": { | ||
"clusterIP": "10.250.83.45", | ||
"ports": [ | ||
{ | ||
"port": 80, | ||
"protocol": "TCP", | ||
"targetPort": 80 | ||
} | ||
], | ||
"selector": { | ||
"app": "foo" | ||
}, | ||
"sessionAffinity": "None", | ||
"type": "ClusterIP" | ||
}, | ||
"status": { | ||
"loadBalancer": {} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
apiVersion: v1 | ||
kind: ConfigMap | ||
metadata: | ||
namespace: default | ||
name: bar | ||
data: | ||
foo: bar |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
apiVersion: apiextensions.k8s.io/v1beta1 | ||
kind: CustomResourceDefinition | ||
metadata: | ||
name: tests.pharos-test.k8s.io | ||
spec: | ||
group: pharos-test.k8s.io | ||
version: v0 | ||
names: | ||
kind: Test | ||
plural: tests | ||
scope: Namespaced |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
apiVersion: v1 | ||
kind: Service | ||
metadata: | ||
namespace: default | ||
name: foo | ||
spec: | ||
selector: | ||
app: foo | ||
type: ClusterIP | ||
ports: | ||
- port: 80 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
apiVersion: pharos-test.k8s.io/v0 | ||
kind: Test | ||
metadata: | ||
name: test | ||
namespace: default | ||
spec: | ||
test: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
RSpec.describe K8s::Util do | ||
describe '#compact_map' do | ||
it "returns an empty array for an empty array" do | ||
expect(described_class.compact_map([]) { |args| args.map(&:to_s) }).to eq [] | ||
end | ||
|
||
it "returns an array of nil for an array of nil" do | ||
expect(described_class.compact_map([nil]) { |args| args.map(&:to_s) }).to eq [nil] | ||
end | ||
|
||
it "translates non-nil values" do | ||
expect(described_class.compact_map([1]) { |args| args.map(&:to_s) }).to eq ['1'] | ||
end | ||
|
||
it "translates non-nil values and passes through nil values" do | ||
expect(described_class.compact_map([nil, 1]) { |args| args.map(&:to_s) }).to eq [nil, '1'] | ||
end | ||
|
||
it "handles duplicates" do | ||
expect(described_class.compact_map([nil, 1, 2, 1]) { |args| args.map(&:to_s) }).to eq [nil, '1', '2', '1'] | ||
end | ||
end | ||
end |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because of how the hash is used, any duplicate args will map to the same return value... shouldn't be a problem when used with idempotent methods like
GET
requests, but it's a limitation.