def test_controller_full_update(self):
        """Test an update that triggers all objects"""
        controller = ProxyKubernetesController(self.outpost,
                                               self.service_connection)

        self.assertIsNone(controller.up())
        with patch("authentik.outposts.controllers.k8s.base.get_version",
                   MagicMock(return_value="1234")):
            self.assertIsNone(controller.up())
        deployment_reconciler = DeploymentReconciler(controller)
        deployment = deployment_reconciler.retrieve()
        self.assertEqual(
            deployment.metadata.labels["app.kubernetes.io/version"], "1234")
        controller.down()
Exemplo n.º 2
0
 def get_reference_object(self) -> V1Service:
     """Get deployment object for outpost"""
     meta = self.get_object_meta(name=self.name)
     ports = []
     for port in self.controller.deployment_ports:
         ports.append(
             V1ServicePort(
                 name=port.name,
                 port=port.port,
                 protocol=port.protocol.upper(),
                 target_port=port.inner_port or port.port,
             ))
     if self.is_embedded:
         selector_labels = {
             "app.kubernetes.io/name": "authentik",
             "app.kubernetes.io/component": "server",
         }
     else:
         selector_labels = DeploymentReconciler(
             self.controller).get_pod_meta()
     return V1Service(
         metadata=meta,
         spec=V1ServiceSpec(
             ports=ports,
             selector=selector_labels,
             type=self.controller.outpost.config.kubernetes_service_type,
         ),
     )
Exemplo n.º 3
0
 def get_reference_object(self) -> V1Service:
     """Get deployment object for outpost"""
     meta = self.get_object_meta(name=self.name)
     ports = []
     for port in self.controller.deployment_ports:
         ports.append(
             V1ServicePort(
                 name=port.name,
                 port=port.port,
                 protocol=port.protocol.upper(),
                 target_port=port.port,
             ))
     selector_labels = DeploymentReconciler(self.controller).get_pod_meta()
     return V1Service(
         metadata=meta,
         spec=V1ServiceSpec(ports=ports,
                            selector=selector_labels,
                            type="ClusterIP"),
     )
    def test_deployment_reconciler(self):
        """test that deployment requires update"""
        controller = ProxyKubernetesController(self.outpost,
                                               self.service_connection)
        deployment_reconciler = DeploymentReconciler(controller)

        self.assertIsNotNone(deployment_reconciler.retrieve())

        config = self.outpost.config
        config.kubernetes_replicas = 3
        self.outpost.config = config

        with self.assertRaises(NeedsUpdate):
            deployment_reconciler.reconcile(
                deployment_reconciler.retrieve(),
                deployment_reconciler.get_reference_object(),
            )

        with CONFIG.patch("outposts.container_image_base", "test"):
            with self.assertRaises(NeedsUpdate):
                deployment_reconciler.reconcile(
                    deployment_reconciler.retrieve(),
                    deployment_reconciler.get_reference_object(),
                )

        deployment_reconciler.delete(
            deployment_reconciler.get_reference_object())