def __init__(self, *args, **kwargs):
     self.log = make_logger()
     self.log.debug("Creating RubinTokenAuthenticator")
     # Superclass gives us the Rubin Manager
     super().__init__(*args, **kwargs)
     self.auth_refresh_age = 900
     self.header_name = "X-Portal-Authorization"
     self.header_is_authorization = True
     self.username_claim_field = "uid"
     self.cached_auth_state = {}
Exemplo n.º 2
0
    def __init__(self, args=None):
        self.logger = make_logger()
        self.repo = None
        if not args:
            raise ValueError("args must be set!")
        self.args = args
        self.debug = False
        if args.debug:
            self.debug = True
        if self.debug:
            self.logger.setLevel(logging.DEBUG)
            self.logger.debug("Debug logging enabled.")
        namespace = self.args.namespace
        if not namespace:
            self.logger.warning("Using kubernetes namespace 'default'")
            namespace = "default"
        self.namespace = namespace
        load_k8s_config()
        self.client = client.CoreV1Api()
        self.images = []
        self.nodes = []
        self.pod_specs = {}
        self.created_pods = []

        self.logger.debug("Arguments: %s" % str(args))
        self.command = self.args.command
        self.cachefile = self.args.cachefile
        if self.args.list:
            for image in self.args.list:
                # Make fully-qualified image name
                colons = image.count(":")
                if colons == 0:
                    image = image + ":latest"
                slashes = image.count("/")
                if slashes == 0:
                    image = "library/" + image
                if slashes == 1:
                    image = "registry.hub.docker.com/" + image
            self.images.append(image)
        # Cheap way to deduplicate lists
        self.images = list(set(self.images))
        # Not portable to non-Unixy systems.
        if self.args.timeout >= 0:
            self.logger.debug("Setting timeout to %d s." % self.args.timeout)
            signal.signal(signal.SIGALRM, self._timeout_handler)
            signal.alarm(self.args.timeout)
        self.config = RubinConfig()
        secname = self.config.pull_secret_name
        pull_secret = get_pull_secret(secname, self.client, self.logger)
        self.pull_secret_reflist = []
        if pull_secret:
            ensure_pull_secret(pull_secret, self.namespace, self.client,
                               self.logger)
            self.pull_secret_reflist = get_pull_secret_reflist(secname)
Exemplo n.º 3
0
 def __init__(self, *args, **kwargs):
     if not self.log:
         self.log = make_logger()
     super().__init__(*args, **kwargs)
     self.delete_grace_period = 25  # K8s takes ten or so, usually
     self.namespace = self.get_user_namespace()
     try:
         self.log.debug("Loading K8s config.")
         config.load_incluster_config()
     except ConfigException:
         config.load_kube_config()
     self.log.debug("Spawner __init__ done.  Namespace '{}'.".format(
         self.namespace))
Exemplo n.º 4
0
 def __init__(self, *args, **kwargs):
     self.log = make_logger()
     super().__init__(*args, **kwargs)
     self.log.debug("Creating RubinSpawner.")
     # Our API and our RBAC API are set in the super() __init__()
     # We want our own Rubin Manager per spawner.
     user = self.user
     if not user:
         self.log.error("No user found!")
         raise RuntimeError("Could not create spawner!")
     auth = user.authenticator
     if not auth:
         self.log.error("No authenticator found!")
         raise RuntimeError("Could not create spawner!")
     self.log.debug("Creating Rubin Manager from authenticated user.")
     self.rubin_mgr = RubinMiddleManager(
         parent=self,
         authenticator=auth,
         spawner=self,
         user=user,
         config=RubinConfig(),
     )
     self.log.debug("Initialized {}".format(__name__))
     self.cached_auth_state = {}
     self.delete_grace_period = 5
     # In the Rubin setup, there is a "provisionator" user, uid/gid 769,
     #  that is who we should start as, unless we are running sudoless.
     # If we are, we set the uid/gid/supplemental gids accordingly.
     self.uid = 769
     self.gid = 769
     self.supplemental_gids = []
     # The fields need to be defined; we don't use them.
     self.fs_gid = None
     self.extra_labels = {}
     self.extra_annotations = {}
     self.image_pull_secrets = None
     self.privileged = False
     self.working_dir = None
     self.lifecycle_hooks = {}  # This one will be useful someday.
     self.init_containers = []
     self.lab_service_account = None
     self.extra_container_config = {}
     self.extra_pod_config = {}
     self.extra_containers = []
Exemplo n.º 5
0
 def _setup_logger(self, level=logging.WARNING, override_root=False):
     # In Python 3.8 we could use force=True to force the root logger
     #  to override existing defaults
     #
     # Don't eliot-log this or load_from_environment or
     #  create_derived_settings, because we initialize an LSSTConfig when
     #  we import jupyterhubutils, and we don't necessarily want to
     #  spam everyone about it
     # Add our formats
     fstr = "[%(levelname).1s %(asctime)s.%(msecs).03d"
     fstr += " %(module)s:%(funcName)s:%(lineno)d] %(message)s"
     dstr = "%Y-%m-%d %H:%M:%S"
     self.log_format = fstr
     self.log_datefmt = dstr
     self.log_level = level
     to_file(sys.stderr)
     if override_root:
         self.eliotify_root_logger(level=level)
     self.log = make_logger(level=level)
Exemplo n.º 6
0
 def __init__(
     self,
     host="hub.docker.com",
     path="",
     owner="",
     name="",
     experimentals=0,
     dailies=3,
     weeklies=2,
     releases=1,
     recommended=True,
     port=None,
     cachefile=None,
     insecure=False,
     debug=False,
 ):
     self.data = {}
     self.display_tags = []
     self._results = None
     self._results_map = {}
     self._name_to_manifest = {}
     self._all_tags = []
     self._reduced_results = []
     self.last_scan = datetime.datetime(1970, 1, 1)  # The Epoch
     self.debug = debug
     self.logger = make_logger()
     if self.debug:
         self.logger.setLevel(logging.DEBUG)
         self.logger.debug("Debug logging enabled.")
     self.host = host
     self.path = path
     self.owner = owner
     self.name = name
     self.experimentals = experimentals
     self.dailies = dailies
     self.weeklies = weeklies
     self.releases = releases
     self.recommended = recommended
     protocol = "https"
     self.insecure = insecure
     if self.insecure:
         protocol = "http"
     exthost = self.host
     reghost = exthost
     if reghost == "hub.docker.com":
         reghost = "registry.hub.docker.com"
     if port:
         exthost += ":" + str(port)
         reghost += ":" + str(port)
     self.reghost = reghost
     self.cachefile = cachefile
     if self.cachefile:
         self._read_cachefile()
     self.registry_url = (
         protocol
         + "://"
         + reghost
         + "/v2/"
         + self.owner
         + "/"
         + self.name
         + "/"
     )
     self.logger.debug("Registry URL: {}".format(self.registry_url))
     self.config = RubinConfig()
     load_k8s_config()
     self.client = CoreV1Api()
Exemplo n.º 7
0
 def __init__(self, *args, **kwargs):
     self.log = make_logger()
     self.log.debug("Creating {}".format(self.__class__.__name__))