From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Filipp Gunbin Newsgroups: gmane.emacs.devel Subject: tramp-kubernetes Date: Mon, 03 Oct 2022 23:30:50 +0300 Message-ID: Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="35222"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: bjc@spork.org, bjc@kublai.com To: emacs-devel@gnu.org, Michael.Albinus@gmx.de Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Mon Oct 03 23:40:53 2022 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ofTBE-0008xn-Nq for ged-emacs-devel@m.gmane-mx.org; Mon, 03 Oct 2022 23:40:53 +0200 Original-Received: from localhost ([::1]:44508 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ofTBD-00066r-JC for ged-emacs-devel@m.gmane-mx.org; Mon, 03 Oct 2022 17:40:51 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:42574) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ofS5e-00011p-LO for emacs-devel@gnu.org; Mon, 03 Oct 2022 16:31:06 -0400 Original-Received: from wout2-smtp.messagingengine.com ([64.147.123.25]:48273) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ofS5a-0003dy-OU for emacs-devel@gnu.org; Mon, 03 Oct 2022 16:31:00 -0400 Original-Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.west.internal (Postfix) with ESMTP id A374F3200094; Mon, 3 Oct 2022 16:30:54 -0400 (EDT) Original-Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Mon, 03 Oct 2022 16:30:54 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fastmail.fm; h= cc:cc:content-type:date:date:from:from:in-reply-to:message-id :mime-version:reply-to:sender:subject:subject:to:to; s=fm3; t= 1664829054; x=1664915454; bh=WRaNW7Ft8k6fV0B/eyrZsLp2j5/gCDgxguR WsdcdAUw=; b=axW2dDUcMyNz9qqriPgPnNs+Q4UZs30I1f0h9ygimtDrjyjNF4p EPAOjqLqkdZF2EjNOXhpF8tWZXNjoZXbxhjxJuD8vOzb+8BQMVdQWlC/V+x5trrs P9OPM6phhKhiWz4ow/qf6tNsU4D9GBIflXO7IuY6QLpzUmt9rbLS9AjArQpKOHXz xVd/sDjXZJfAGVirbVJG8TjhKe+9kYuXy8TF58F/2hiDY2O4vKkGuvAagntnPWis vFSJpxtqWEu/JEypGi6Bn3gtzP9QgV9dOXC6t4BJ86w3//lhpQy5P3W4D25rnXf/ wxQ7t1aVR8wRfR1P2HkQgHkoNwfUX2aodfA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:date:date:feedback-id :feedback-id:from:from:in-reply-to:message-id:mime-version :reply-to:sender:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm2; t=1664829054; x= 1664915454; bh=WRaNW7Ft8k6fV0B/eyrZsLp2j5/gCDgxguRWsdcdAUw=; b=t Jsg/IHqhtKZQxRHLKnJid/e7NytrIh37JXozImV6UHfdNpynncvU75fDEZnb7FKE 3E71xZD3HRWzLWdee03c5hSxYBk8iIfx/t5dS37eMcs8Eyi8lXQUTqjCJJhVy/Fl pdyfJUD1+s8zH+LG5899t3q2dsn/R/KOr0jJUyF8CIbJQZ/BVBBLx5sRWFi9KCA6 xbxOED3tSfLe2u0l7VsUdweIK4bFBIhKdlXCMInSz7Zcj7xkvISoJkWjtt1tWF+6 QuwnzpOHTK2tci/59NEWiSqktMm4cLQwhLio8VGDLdIQw/lYlE8lB3l6LUNUm2ON L0GoEI5scxrIuBCv3m00g== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvfedrfeehledgudegkecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecunecujfgurhephffvvefufgffkfggtgesmhdtre ertdertdenucfhrhhomhephfhilhhiphhpucfiuhhnsghinhcuoehfghhunhgsihhnsehf rghsthhmrghilhdrfhhmqeenucggtffrrghtthgvrhhnpeevveffgffhledvlefgfeejhf evgeeugeehffelvedthedtudelffdvudetgfehleenucevlhhushhtvghrufhiiigvpedt necurfgrrhgrmhepmhgrihhlfhhrohhmpehfghhunhgsihhnsehfrghsthhmrghilhdrfh hm X-ME-Proxy: Feedback-ID: id48c41f1:Fastmail Original-Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 3 Oct 2022 16:30:52 -0400 (EDT) Mail-Followup-To: emacs-devel@gnu.org, Michael.Albinus@gmx.de, bjc@spork.org, bjc@kublai.com Received-SPF: pass client-ip=64.147.123.25; envelope-from=fgunbin@fastmail.fm; helo=wout2-smtp.messagingengine.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:296797 Archived-At: --=-=-= Content-Type: text/plain Hi, I've seen the recently-added tramp-docker method (thanks for that!). It was easy to adapt that to add a method for Kubernetes. I think this could be a worthwhile addition, the code is attached - take if you like. Of the things to be improved, we could add container selection (like "kubectl exec -c "). Now it offers to choose pod, and then uses first container there (as just "kubectl exec "). This default should usually be enough, though. Thanks. Filipp --=-=-= Content-Type: application/emacs-lisp Content-Disposition: attachment; filename=tramp-kubernetes.el Content-Transfer-Encoding: quoted-printable ;;; tramp-kubernetes.el --- Tramp integration for Kubernetes containers -*= - lexical-binding: t; -*- ;; Copyright =C2=A9 2022 Free Software Foundation, Inc. ;; Keywords: comm, processes, kubernetes ;; Package: tramp ;; This file is part of GNU Emacs. ;; GNU Emacs is free software: you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by ;; the Free Software Foundation, either version 3 of the License, or ;; (at your option) any later version. ;; GNU Emacs is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;; GNU General Public License for more details. ;; You should have received a copy of the GNU General Public License ;; along with GNU Emacs. If not, see . ;;; Commentary: ;; `tramp-kubernetes' allows Tramp access to environments provided by ;; Kubernetes. ;; ;; The kubectl program should be configured correctly. You may also ;; want to set the namespace to use (otherwise you'll be getting the ;; possibly long list equivalent to what "get -A" returns): ;; ;; kubectl config set-context --current --namespace=3D ;; ;; ## Usage ;; ;; Open a file in container: ;; ;; C-x C-f /kubernetes:POD:/path/to/file ;; ;; Where: ;; POD is the pod to connect to. ;; By default, the first container in that pod will be ;; connected to. ;;; Code: (require 'tramp) ;;;###tramp-autoload (defcustom tramp-kubernetes-program "kubectl" "Name of the Kubernetes client program." :group 'tramp :version "29.1" :type '(choice (const "kubectl") (string))) ;;;###tramp-autoload (defconst tramp-kubernetes-method "kubernetes" "Tramp method name to use to connect to Kubernetes containers.") ;;;###tramp-autoload (defun tramp-kubernetes--completion-function (&rest _args) "List Kubernetes pods available for connection. This function is used by `tramp-set-completion-function', please see its function help for a description of the format." (when-let ((raw-list (shell-command-to-string (concat tramp-kubernetes-program " get pods --no-headers " "-o custom-columns=3DNAME:.metadata.name"))) (names (split-string raw-list "\n" 'omit))) (mapcar (lambda (name) (list nil name)) names))) ;;;###tramp-autoload (defvar tramp-default-remote-shell) ;; Silence byte compiler. ;;;###tramp-autoload (tramp--with-startup (push `(,tramp-kubernetes-method (tramp-login-program ,tramp-kubernetes-program) (tramp-login-args (("exec") ("%h") ("-it") ("--") ("%l"))) (tramp-remote-shell ,tramp-default-remote-shell) (tramp-remote-shell-login ("-l")) (tramp-remote-shell-args ("-i" "-c"))) tramp-methods) (tramp-set-completion-function tramp-kubernetes-method '((tramp-kubernetes--completion-function "")))) (add-hook 'tramp-unload-hook (lambda () (unload-feature 'tramp-kubernetes 'force))) (provide 'tramp-kubernetes) ;;; tramp-kubernetes.el ends here --=-=-=--