示例#1
0
 def create_agent_secret(self, secret="testing123"):
     if not k8s.has_secret("signalfx-agent", namespace=self.namespace):
         print('Creating secret "signalfx-agent" ...')
         k8s.create_secret("signalfx-agent",
                           "access-token",
                           secret,
                           namespace=self.namespace)
示例#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,
                    )