Skip to content

Commit

Permalink
adding proxy set up
Browse files Browse the repository at this point in the history
Signed-off-by: Paige Patton <[email protected]>
  • Loading branch information
paigerube14 committed Dec 3, 2024
1 parent 547f29b commit 8a7ad0a
Show file tree
Hide file tree
Showing 15 changed files with 136 additions and 60 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Create multi-node KinD cluster
uses: redhat-chaos/actions/kind@main
uses: paigerube14/actions/kind@update_kind

- name: get nodes
run: |
Expand Down
4 changes: 2 additions & 2 deletions src/krkn_lib/elastic/krkn_elastic.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@

import datetime
import logging
import math
import time

import math
import urllib3
from elasticsearch import Elasticsearch, NotFoundError
from elasticsearch_dsl import Search

from krkn_lib.models.elastic.models import (
ElasticAlert,
ElasticMetric,
ElasticChaosRunTelemetry,
ElasticMetric,
)
from krkn_lib.models.telemetry import ChaosRunTelemetry
from krkn_lib.utils.safe_logger import SafeLogger
Expand Down
57 changes: 40 additions & 17 deletions src/krkn_lib/k8s/krkn_kubernetes.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from functools import partial
from queue import Queue
from typing import Any, Dict, List, Optional
from urllib.parse import urlparse

import arcaflow_lib_kubernetes
import kubernetes
Expand All @@ -37,7 +38,7 @@
Volume,
VolumeMount,
)
from krkn_lib.models.telemetry import NodeInfo, Taint, ClusterEvent
from krkn_lib.models.telemetry import ClusterEvent, NodeInfo, Taint
from krkn_lib.utils import filter_dictionary, get_random_string
from krkn_lib.utils.safe_logger import SafeLogger

Expand Down Expand Up @@ -144,20 +145,41 @@ def __initialize_clients(self, kubeconfig_path: str = None):
conf.use_context("krkn-context")

try:
config.load_kube_config(kubeconfig_path)
# config.load_kube_config(kubeconfig_path)

client_config = client.Configuration()
http_proxy = os.getenv("http_proxy", None)
if http_proxy and "@" in http_proxy:
proxy_auth = urlparse(http_proxy)
auth_string = proxy_auth.username + ":" + proxy_auth.password
client_config.username = proxy_auth.username
client_config.password = proxy_auth.password
config.load_kube_config(
kubeconfig_path,
client_configuration=client_config,
)

proxy_url = http_proxy
if proxy_url:
client_config.proxy = proxy_url
if proxy_auth:
client_config.proxy_headers = urllib3.util.make_headers(
proxy_basic_auth=auth_string
)

client.Configuration.set_default(client_config)

self.api_client = client.ApiClient()
self.k8s_client = config.new_client_from_config(
config_file=kubeconfig_path
)
self.cli = client.CoreV1Api(self.k8s_client)

self.cli = client.CoreV1Api(self.api_client)
self.version_client = client.VersionApi(self.api_client)
self.apps_api = client.AppsV1Api(self.api_client)
self.batch_cli = client.BatchV1Api(self.k8s_client)
self.batch_cli = client.BatchV1Api(self.api_client)
self.net_cli = client.NetworkingV1Api(self.api_client)
self.custom_object_client = client.CustomObjectsApi(
self.k8s_client
self.api_client
)
self.dyn_client = DynamicClient(self.k8s_client)
self.dyn_client = DynamicClient(self.api_client)
self.watch_resource = watch.Watch()

except OSError:
Expand Down Expand Up @@ -1127,11 +1149,12 @@ def exec_command_on_node(
pod_body = yaml.safe_load(
pod_template.render(nodename=node_name, podname=exec_pod_name)
)

logging.info(
f"Creating pod to exec command {command} on node {node_name}"
)
try:
self.create_pod(pod_body, exec_pod_namespace, 300)
self.create_pod(pod_body, exec_pod_namespace, 500)
except Exception as e:
logging.error(
f"failed to create pod {exec_pod_name} on node {node_name},"
Expand Down Expand Up @@ -1498,10 +1521,12 @@ def apply_yaml(self, path, namespace="default") -> list[str]:
the resource (optional default `default`)
:return: the list of names of created objects
"""

return utils.create_from_yaml(
self.api_client, yaml_file=path, namespace=namespace
)
try:
return utils.create_from_yaml(
self.api_client, yaml_file=path, namespace=namespace
)
except Exception as e:
logging.error("Error trying to apply_yaml" + str(e))

def get_pod_info(self, name: str, namespace: str = "default") -> Pod:
"""
Expand Down Expand Up @@ -1712,9 +1737,7 @@ def find_kraken_node(self) -> str:
raise e
return node_name

def watch_node_status(
self, node: str, status: str, timeout: int
):
def watch_node_status(self, node: str, status: str, timeout: int):
"""
Watch for a specific node status
Expand Down
12 changes: 6 additions & 6 deletions src/krkn_lib/models/elastic/models.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import datetime

from elasticsearch_dsl import (
Keyword,
Text,
Date,
Document,
Float,
Long,
Nested,
InnerDoc,
Integer,
Keyword,
Long,
Nested,
Text,
)
import datetime

from krkn_lib.models.telemetry import ChaosRunTelemetry

Expand Down Expand Up @@ -195,4 +196,3 @@ def __init__(
self.cloud_type = chaos_run_telemetry.cloud_type
self.cluster_version = chaos_run_telemetry.cluster_version
self.run_uuid = chaos_run_telemetry.run_uuid

5 changes: 4 additions & 1 deletion src/krkn_lib/models/telemetry/models.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
from __future__ import annotations

import base64
import json
import yaml
from dataclasses import dataclass
from datetime import datetime, timezone

import yaml

from krkn_lib.models.k8s import PodsStatus

relevant_event_reasons: frozenset[str] = frozenset(
Expand Down
1 change: 1 addition & 0 deletions src/krkn_lib/telemetry/ocp/krkn_telemetry_openshift.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import os
import threading
from queue import Queue

from krkn_lib.models.telemetry import ChaosRunTelemetry
from krkn_lib.ocp import KrknOpenshift
from krkn_lib.telemetry.k8s import KrknTelemetryKubernetes
Expand Down
10 changes: 8 additions & 2 deletions src/krkn_lib/tests/base_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def setUpClass(cls):
cls.lib_telemetry_ocp = KrknTelemetryOpenshift(
SafeLogger(), cls.lib_ocp
)
host = cls.lib_k8s.api_client.configuration.host
host = cls.lib_k8s.get_host()
logging.disable(logging.CRITICAL)
# PROFILER
# """init each test"""
Expand Down Expand Up @@ -103,6 +103,7 @@ def deploy_namespace(self, name: str, labels: List[Dict[str, str]]):
template = self.template_to_namespace(name, labels)
self.apply_template(template)


def deploy_fedtools(
self,
namespace: str = "default",
Expand Down Expand Up @@ -266,7 +267,12 @@ def apply_template(self, template: str):
with tempfile.NamedTemporaryFile(mode="w") as file:
file.write(template)
file.flush()
self.lib_k8s.apply_yaml(file.name, "")
retries = 3
while retries > 0:
template_applied = self.lib_k8s.apply_yaml(file.name, namespace="")
if template_applied is not None:
return
retries -= 1

def get_random_string(self, length: int) -> str:
letters = string.ascii_lowercase
Expand Down
6 changes: 1 addition & 5 deletions src/krkn_lib/tests/test_krkn_elastic.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
import datetime
import time

import uuid

from krkn_lib.elastic.krkn_elastic import KrknElastic
from krkn_lib.models.elastic.models import (
ElasticAlert,
ElasticMetric,
)
from krkn_lib.models.elastic.models import ElasticAlert, ElasticMetric
from krkn_lib.models.telemetry import ChaosRunTelemetry
from krkn_lib.tests import BaseTest
from krkn_lib.utils import SafeLogger
Expand Down
Loading

0 comments on commit 8a7ad0a

Please sign in to comment.