Ejemplo n.º 1
0
 def create_agent_configmap(self, configmap_path):
     self.configmap_yaml = yaml.load(open(configmap_path).read())
     self.configmap_name = self.configmap_yaml["metadata"]["name"]
     self.delete_agent_configmap()
     self.agent_yaml = yaml.load(self.configmap_yaml["data"]["agent.yaml"])
     del self.agent_yaml["observers"]
     if not self.observer and "observers" in self.agent_yaml.keys():
         del self.agent_yaml["observers"]
     elif self.observer == "k8s-api":
         self.agent_yaml["observers"] = [{
             "type": self.observer,
             "kubernetesAPI": {
                 "authType": "serviceAccount",
                 "skipVerify": False
             }
         }]
     elif self.observer == "k8s-kubelet":
         self.agent_yaml["observers"] = [{
             "type": self.observer,
             "kubeletAPI": {
                 "authType": "serviceAccount",
                 "skipVerify": True
             }
         }]
     elif self.observer == "docker":
         self.agent_yaml["observers"] = [{
             "type":
             self.observer,
             "dockerURL":
             "unix:///var/run/docker.sock"
         }]
     else:
         self.agent_yaml["observers"] = [{"type": self.observer}]
     self.agent_yaml["globalDimensions"][
         "kubernetes_cluster"] = self.cluster_name
     self.agent_yaml["intervalSeconds"] = 5
     self.agent_yaml["sendMachineID"] = True
     self.agent_yaml["useFullyQualifiedHost"] = False
     self.agent_yaml["internalStatusHost"] = get_internal_status_host()
     if self.backend:
         self.agent_yaml["ingestUrl"] = "http://%s:%d" % (
             self.backend.ingest_host, self.backend.ingest_port)
         self.agent_yaml["apiUrl"] = "http://%s:%d" % (
             self.backend.api_host, self.backend.api_port)
     if "metricsToExclude" in self.agent_yaml.keys():
         del self.agent_yaml["metricsToExclude"]
     del self.agent_yaml["monitors"]
     self.agent_yaml["monitors"] = self.monitors
     self.configmap_yaml["data"]["agent.yaml"] = yaml.dump(self.agent_yaml)
     print(
         "Creating configmap for observer=%s and monitor(s)=%s from %s ..."
         % (self.observer, ",".join([m["type"] for m in self.monitors
                                     ]), configmap_path))
     create_configmap(body=self.configmap_yaml, namespace=self.namespace)
Ejemplo n.º 2
0
    def deploy(self, agent_yaml=None, wait_for_ready=True):
        with self.deploy_unique_rbac_resources():
            secret = None
            daemonset = None
            configmap = None
            try:
                secret = utils.create_secret("signalfx-agent",
                                             "access-token",
                                             "testing123",
                                             namespace=self.namespace)
                print("Created agent secret")

                configmap_base = load_resource_yaml(AGENT_CONFIGMAP_PATH)
                self.fill_in_configmap(configmap_base, agent_yaml)
                configmap = utils.create_configmap(body=configmap_base,
                                                   namespace=self.namespace)
                print(f"Created agent configmap:\n{configmap_base}")

                daemonset_base = load_resource_yaml(AGENT_DAEMONSET_PATH)
                daemonset_base["spec"]["template"]["spec"]["containers"][0][
                    "imagePullPolicy"] = "Always"
                daemonset_base["spec"]["template"]["spec"]["containers"][0][
                    "image"] = self.agent_image_name
                daemonset_base["spec"]["template"]["spec"]["containers"][0][
                    "resources"] = {
                        "requests": {
                            "cpu": "50m"
                        }
                    }
                daemonset = utils.create_daemonset(
                    body=daemonset_base,
                    namespace=self.namespace,
                    wait_for_ready=wait_for_ready)
                print(f"Created agent daemonset:\n{daemonset_base}")

                yield
            finally:
                print("\nAgent status:\n%s" % self.get_status())
                print("\nAgent logs:\n%s" % self.get_logs())
                if daemonset:
                    utils.delete_daemonset(daemonset.metadata.name,
                                           namespace=self.namespace)
                if configmap:
                    utils.delete_configmap(configmap.metadata.name,
                                           namespace=self.namespace)
                if secret:
                    corev1 = kube_client.CoreV1Api()
                    corev1.delete_namespaced_secret(
                        name=secret.metadata.name,
                        body=kube_client.V1DeleteOptions(
                            grace_period_seconds=0,
                            propagation_policy="Background"),
                        namespace=secret.metadata.namespace,
                    )