Skip to content

Commit

Permalink
Proxy setting fix (#129)
Browse files Browse the repository at this point in the history
  • Loading branch information
m-wcislo authored Apr 10, 2023
1 parent 6834e3c commit c238ef0
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 7 deletions.
2 changes: 2 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ jobs:
- k3d/k3d-run:
step-name: Prerequisites for 1st cluster
command: |
sleep 10
kubectl version
helm repo add grafana https://grafana.github.io/helm-charts
helm repo update
helm install grafana grafana/grafana -f /repo/testcases/grafana/values.yaml
Expand Down
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,16 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## In progress
- Add proxy configuration fetched from `HTTP_PROXY` or `http_proxy` environment variable

## [0.8.4] - 2022-04-10
### Fixed
- Fixed proxy setting
- Deprecating batch/v1beta1, discovery.k8s.io/v1beta1

## [0.8.3] - 2022-12-19
revert

- Add proxy configuration fetched from `HTTP_PROXY` or `http_proxy` environment variable by [@LissaGreense]
## [0.8.0] - 2022-10-27
### Added
- Add function list_namespaced_stateful_set_by_pattern [#114](https://github.com/devopsspiral/KubeLibrary/pull/113) by [@siaomingjeng](https://github.com/siaomingjeng)
Expand Down
8 changes: 6 additions & 2 deletions src/KubeLibrary/KubeLibrary.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ def __init__(self, kube_config=None, context=None, api_url=None, bearer_token=No
self.reload_config(kube_config=kube_config, context=context, api_url=api_url, bearer_token=bearer_token,
ca_cert=ca_cert, incluster=incluster, cert_validation=cert_validation)

@staticmethod
def get_proxy():
return environ.get('https_proxy') or environ.get('HTTPS_PROXY') or environ.get('http_proxy') or environ.get('HTTP_PROXY')

@staticmethod
def generate_alphanumeric_str(size):
"""Generates a random alphanumeric string with given size.
Expand Down Expand Up @@ -247,6 +251,7 @@ def reload_config(self, kube_config=None, context=None, api_url=None, bearer_tok
if bearer_token.startswith('Bearer '):
raise BearerTokenWithPrefixException
configuration = client.Configuration()
configuration._default.proxy = KubeLibrary.get_proxy()
configuration.api_key["authorization"] = bearer_token
configuration.api_key_prefix['authorization'] = 'Bearer'
configuration.host = api_url
Expand All @@ -255,14 +260,13 @@ def reload_config(self, kube_config=None, context=None, api_url=None, bearer_tok
else:
try:
config.load_kube_config(kube_config, context)
client.Configuration._default.proxy = KubeLibrary.get_proxy()
except TypeError:
logger.error('Neither KUBECONFIG nor ~/.kube/config available.')

if not self.api_client:
self.api_client = client.ApiClient(configuration=client.Configuration().get_default_copy())

self.api_client.configuration.proxy = environ.get('http_proxy') or environ.get('HTTP_PROXY')

self._add_api('v1', client.CoreV1Api)
self._add_api('networkingv1api', client.NetworkingV1Api)
self._add_api('batchv1', client.BatchV1Api)
Expand Down
2 changes: 1 addition & 1 deletion src/KubeLibrary/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version = "0.8.3"
version = "0.8.4"
2 changes: 1 addition & 1 deletion test-objects-chart/templates/cronjob.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
apiVersion: batch/v1beta1
apiVersion: batch/v1
kind: CronJob
metadata:
name: hello
Expand Down
2 changes: 1 addition & 1 deletion testcases/custom_objects/custom_objects.robot
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ Get Cluster Custom Object

Get Namespaced Custom Object
[Tags] smoke
${fo}= Get Namespaced Custom Object discovery.k8s.io v1beta1 default endpointslices kubernetes
${fo}= Get Namespaced Custom Object discovery.k8s.io v1 default endpointslices kubernetes
Should Be Equal As Strings ${fo}[metadata][name] kubernetes
Should Be Equal As Strings ${fo}[addressType] IPv4
2 changes: 1 addition & 1 deletion testcases/dynamic_client/dynamic_client_kw.robot
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ discover resources
[Arguments] ${namespace}
${deployments}= get resource names Deployment apps/v1 ${namespace}
${statefulsets}= get resource names StatefulSet apps/v1 ${namespace}
${cronjobs}= get resource names CronJob batch/v1beta1 ${namespace}
${cronjobs}= get resource names CronJob batch/v1 ${namespace}
${secrets}= get resource names Secret v1 ${namespace}
${configmaps}= get resource names ConfigMap v1 ${namespace}
${found}= BuiltIn.evaluate ${deployments} + ${statefulsets} + ${cronjobs} + ${secrets} + ${configmaps}
Expand Down

0 comments on commit c238ef0

Please sign in to comment.