Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions lib/rest.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ def self.get_base_opts(user:, auth: nil)
opts = {}

opts[:options] = {}
opts[:options][:oapi_version] = user.rest_preferences[:oapi_version] ||
user.env.api_version
opts[:options][:api_version] = user.rest_preferences[:api_version] ||
user.env.api_version
opts[:options][:accept] = "application/json"
Expand Down Expand Up @@ -94,7 +92,6 @@ def self.normalize_header_list(_headers)
def self.delegate_rest_request(req, base_opts, req_opts)
## use special hash like class to track usage of supplied options
tracked_opts = UsageTrackingHash.new(base_opts.delete(:options).merge(req_opts))
tracked_opts[:oapi_version] # make sure this is marked accessed
tracked_opts[:api_version] # make sure this is marked accessed

case
Expand Down
2 changes: 1 addition & 1 deletion lib/rest_kubernetes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module Kubernetes
extend Helper

def self.populate(path, base_opts, opts)
populate_common("/api/<api_version>", path, base_opts, opts)
populate_common("/apis/#{path}.k8s.io/<api_version>", path, base_opts, opts)
end

class << self
Expand Down
72 changes: 27 additions & 45 deletions lib/rest_openshift.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ module Rest
module OpenShift
extend Helper

def self.populate(path, base_opts, opts)
populate_common("/oapi/<oapi_version>", path, base_opts, opts)
def self.populate(path, base_opts, opts, type)
populate_common("/apis/#{type}.openshift.io/<api_version>", path, base_opts, opts)
Comment thread
akostadinov marked this conversation as resolved.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using api_version here is not correct. In fact all these something.openshift.io APIs may use different API version. But since it is less broken than before, we can merge as is to get something working. We need more investigation to figure out what might be an approach that makes sense.

/lgtm

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you mean by may use different API version? Shouldn't they all be using the same api version?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well initial assumpion was that there will be one global API version like 1, 2, 3. Now they have multiple something.k8s.io and somehting.openshift.io APIs and each of them can have a different independent API level. Having a single parameter for this will not work.

On the other hand it can be overridden for each call so maybe will work. As long as it works now, I'm fine.

end

class << self
Expand All @@ -21,7 +21,7 @@ class << self
# "gitVersion": "v3.3.0.27",
# "buildDate": "2016-08-29T14:44:33Z"
# }
def self.version(base_opts, opts)
def self.version(base_opts, opts, type="version")
populate_common("/version", "/openshift", base_opts, opts)
return perform(**base_opts, method: "GET") { |res|
res[:props][:openshift] = res[:parsed]["gitVersion"]
Expand All @@ -31,75 +31,73 @@ def self.version(base_opts, opts)
}
end

def self.delete_oauthaccesstoken(base_opts, opts)
populate("/oauthaccesstokens/<token_to_delete>", base_opts, opts)
def self.delete_oauthaccesstoken(base_opts, opts, type="oauth")
populate("/oauthaccesstokens/<token_to_delete>", base_opts, opts, type)
return perform(**base_opts, method: "DELETE")
end

def self.list_projects(base_opts, opts)
populate("/projects", base_opts, opts)
def self.list_projects(base_opts, opts, type="project")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that type here should not be a parameter but hardcoded when calling populate method. Why would we ever want to specify a different type when calling list_projects?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, we can put it here or at the populate method as you suggested

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, please remove this parameter type from here as well other individual calls. populate looks good.

See my other comment. I would leave it to you about merging k8s and openshift calls in same place.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@akostadinov ok, I fixed that now.

populate("/projects", base_opts, opts, type)
return perform(**base_opts, method: "GET")
end

def self.delete_project(base_opts, opts)
populate("/projects/<project_name>", base_opts, opts)
def self.delete_project(base_opts, opts, type="project")
populate("/projects/<project_name>", base_opts, opts, type)
return perform(**base_opts, method: "DELETE")
end

def self.get_project(base_opts, opts)
populate("/projects/<project_name>", base_opts, opts)
def self.get_project(base_opts, opts, type="project")
populate("/projects/<project_name>", base_opts, opts, type)
return perform(**base_opts, method: "GET")
end

def self.get_user(base_opts, opts)
populate("/users/<username>", base_opts, opts)
def self.get_user(base_opts, opts, type="user")
populate("/users/<username>", base_opts, opts, type)
return perform(**base_opts, method: "GET") { |res|
res[:props][:name] = res[:parsed]["metadata"]["name"]
res[:props][:uid] = res[:parsed]["metadata"]["uid"]
}
end

# this usually creates a project in fact
def self.create_project_request(base_opts, opts)
def self.create_project_request(base_opts, opts, type="project")
base_opts[:payload] = {}
# see https://bugzilla.redhat.com/show_bug.cgi?id=1244889 for apiVersion
base_opts[:payload][:apiVersion] = opts[:oapi_version]
base_opts[:payload]["displayName"] = opts[:display_name] if opts[:display_name]
base_opts[:payload]["description"] = opts[:description] if opts[:description]
# base_opts[:payload][:kind] = "ProjectRequest"
base_opts[:payload][:metadata] = {name: opts[:project_name]}

populate("/projectrequests", base_opts, opts)
populate("/projectrequests", base_opts, opts, type)
return Http.request(**base_opts, method: "POST")
end

def self.post_local_resource_access_reviews(base_opts, opts)
def self.post_local_resource_access_reviews(base_opts, opts, type="authorization")
base_opts[:payload] = {}
base_opts[:payload][:apiVersion] = opts[:oapi_version]
base_opts[:payload][:kind] = "LocalResourceAccessReview"
base_opts[:payload][:verb] = opts[:verb]
base_opts[:payload][:resource] = opts[:resource]
project_name = opts[:project_name]
populate("/namespaces/<project_name>/localresourceaccessreviews", base_opts, opts)
populate("/namespaces/<project_name>/localresourceaccessreviews", base_opts, opts, type)
return perform(**base_opts, method: "POST")
end

# did not find out how to use this one yet
def self.create_oauth_access_token(base_opts, opts)
def self.create_oauth_access_token(base_opts, opts, type="oauth")
base_opts[:payload] = {}
base_opts[:payload]["expiresIn"] = opts[:expires_in] if opts[:expires_in]
base_opts[:payload]["userName"] = opts[:user_name] if opts[:user_name]
base_opts[:payload][:scopes] = opts[:scopes] if opts[:scopes]


populate("/oauthaccesstokens", base_opts, opts)
populate("/oauthaccesstokens", base_opts, opts, type)
return perform(**base_opts, method: "POST") { |res|
# res[:props][:name] = res[:parsed]["metadata"]["name"]
# res[:props][:uid] = res[:parsed]["metadata"]["uid"]
}
end

def self.rollback_deploy(base_opts, opts)
def self.rollback_deploy(base_opts, opts, type="apps")
base_opts[:payload] = {}
base_opts[:payload][:spec] = {}
base_opts[:payload][:spec][:from] = {name: opts[:deploy_name]}
Expand All @@ -110,42 +108,26 @@ def self.rollback_deploy(base_opts, opts)

project_name = opts[:project_name]

populate("/namespaces/<project_name>/deploymentconfigrollbacks", base_opts, opts)
populate("/namespaces/<project_name>/deploymentconfigrollbacks", base_opts, opts, type)
return Http.request(**base_opts, method: "POST")
end

def self.get_subresources_oapi(base_opts, opts)
populate("/namespaces/<project_name>/<resource_type>/<resource_name>/status", base_opts, opts)
return Http.request(**base_opts, method: "GET")
end

def self.post_role_oapi(base_opts, opts)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pruan-rht any replacement for this method?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@stuartchuan, for 4.0, oapi has been removed, that's why I took out this method

base_opts[:payload] = {}
base_opts[:payload]["kind"] = opts[:kind]
base_opts[:payload]["apiVersion"] = opts[:api_version]
base_opts[:payload]["verb"] = opts[:verb]
base_opts[:payload]["resource"] = opts[:resource]
base_opts[:payload]["user"] = opts[:user]

populate("/namespaces/<project_name>/<role>", base_opts, opts)
return Http.request(**base_opts, method: "POST")
end

def self.post_pod_security_policy_self_subject_reviews(base_opts, opts)
def self.post_pod_security_policy_self_subject_reviews(base_opts, opts, type="security")
base_opts[:payload] = File.read(expand_path(opts[:payload_file]))
populate("/namespaces/<project_name>/podsecuritypolicyselfsubjectreviews", base_opts, opts)
populate("/namespaces/<project_name>/podsecuritypolicyselfsubjectreviews", base_opts, opts, type)
return perform(**base_opts, method: "POST")
end

def self.post_pod_security_policy_subject_reviews(base_opts, opts)
def self.post_pod_security_policy_subject_reviews(base_opts, opts, type="security")
base_opts[:payload] = File.read(expand_path(opts[:payload_file]))
populate("/namespaces/<project_name>/podsecuritypolicysubjectreviews", base_opts, opts)
populate("/namespaces/<project_name>/podsecuritypolicysubjectreviews", base_opts, opts, type)
return perform(**base_opts, method: "POST")
end

def self.post_pod_security_policy_reviews(base_opts, opts)
def self.post_pod_security_policy_reviews(base_opts, opts, type="security")
base_opts[:payload] = File.read(expand_path(opts[:payload_file]))
populate("/namespaces/<project_name>/podsecuritypolicyreviews", base_opts, opts)
populate("/namespaces/<project_name>/podsecuritypolicyreviews", base_opts, opts, type)
return perform(**base_opts, method: "POST")
end

Expand Down