@backstage/plugin-kubernetes 0.5.2 → 0.5.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,56 @@
1
1
  # @backstage/plugin-kubernetes
2
2
 
3
+ ## 0.5.5
4
+
5
+ ### Patch Changes
6
+
7
+ - edbd626d0a: add a new auth provider to support use GOOGLE_APPLICATION_CREDENTIALS
8
+ - 51fbedc445: Migrated usage of deprecated `IdentityApi` methods.
9
+ - Updated dependencies
10
+ - @backstage/core-components@0.8.5
11
+ - @backstage/core-plugin-api@0.6.0
12
+ - @backstage/plugin-catalog-react@0.6.12
13
+ - @backstage/config@0.1.13
14
+ - @backstage/catalog-model@0.9.10
15
+ - @backstage/plugin-kubernetes-common@0.2.2
16
+
17
+ ## 0.5.5-next.0
18
+
19
+ ### Patch Changes
20
+
21
+ - 51fbedc445: Migrated usage of deprecated `IdentityApi` methods.
22
+ - Updated dependencies
23
+ - @backstage/core-components@0.8.5-next.0
24
+ - @backstage/core-plugin-api@0.6.0-next.0
25
+ - @backstage/config@0.1.13-next.0
26
+ - @backstage/plugin-catalog-react@0.6.12-next.0
27
+ - @backstage/catalog-model@0.9.10-next.0
28
+ - @backstage/plugin-kubernetes-common@0.2.2-next.0
29
+
30
+ ## 0.5.4
31
+
32
+ ### Patch Changes
33
+
34
+ - 7612e2856b: Clean up emptystate.svg image, removing wrong white artifact from the background
35
+ - Updated dependencies
36
+ - @backstage/config@0.1.12
37
+ - @backstage/core-components@0.8.4
38
+ - @backstage/core-plugin-api@0.5.0
39
+ - @backstage/plugin-catalog-react@0.6.11
40
+ - @backstage/catalog-model@0.9.9
41
+
42
+ ## 0.5.3
43
+
44
+ ### Patch Changes
45
+
46
+ - 7ac0bd2c66: implement dashboard link formatter for GKE
47
+ - 4ce51ab0f1: Internal refactor of the `react-use` imports to use `react-use/lib/*` instead.
48
+ - Updated dependencies
49
+ - @backstage/core-plugin-api@0.4.1
50
+ - @backstage/plugin-catalog-react@0.6.10
51
+ - @backstage/plugin-kubernetes-common@0.2.1
52
+ - @backstage/core-components@0.8.3
53
+
3
54
  ## 0.5.2
4
55
 
5
56
  ### Patch Changes
@@ -1 +1 @@
1
- <svg xmlns="http://www.w3.org/2000/svg" width="282" height="173" fill="none" viewBox="0 0 282 173"><path fill="#000" fill-opacity=".05" fill-rule="evenodd" d="M16.4571 45.1637C11.0514 46.1711 7.48574 51.3699 8.49306 56.7756C9.50039 62.1814 14.6992 65.747 20.105 64.7397L27.5528 63.3518C25.4791 65.5835 24.4525 68.7347 25.0535 71.9596C26.0608 77.3653 31.2596 80.931 36.6654 79.9236L89.691 70.0427C89.7016 70.1067 89.7129 70.1708 89.7249 70.2349C90.3258 73.4598 92.4185 76.0298 95.1569 77.3647L91.9031 77.971C86.4974 78.9784 82.9318 84.1772 83.9391 89.583C84.9464 94.9887 90.1452 98.5543 95.551 97.547L250.098 68.7482C255.504 67.7409 259.069 62.5421 258.062 57.1363C257.461 53.9114 255.368 51.3414 252.63 50.0065L257.835 49.0366C263.241 48.0292 266.807 42.8304 265.799 37.4247C264.792 32.0189 259.593 28.4533 254.187 29.4606L161.492 46.7338C161.481 46.6697 161.47 46.6056 161.458 46.5415C160.857 43.3166 158.764 40.7466 156.026 39.4117L165.025 37.7347C170.431 36.7274 173.997 31.5286 172.989 26.1228C171.982 20.7171 166.783 17.1514 161.378 18.1588L16.4571 45.1637ZM24.3031 122.54C23.2958 117.134 26.8614 111.936 32.2672 110.928L190.856 81.3762C196.262 80.3688 201.461 83.9345 202.468 89.3402C203.476 94.746 199.91 99.9448 194.504 100.952L189.963 101.798C190.493 102.057 190.999 102.362 191.474 102.708L246.43 92.4677C251.835 91.4604 257.034 95.026 258.041 100.432C258.642 103.657 257.616 106.808 255.542 109.04L256.649 108.833C262.055 107.826 267.253 111.392 268.261 116.797C269.268 122.203 265.702 127.402 260.297 128.409L95.5591 159.107C90.1534 160.114 84.9545 156.549 83.9472 151.143C82.9399 145.737 86.5055 140.538 91.9113 139.531L103.94 137.29C103.41 137.031 102.904 136.726 102.429 136.38L29.1002 150.044C23.6944 151.051 18.4956 147.486 17.4882 142.08C16.4809 136.674 20.0465 131.475 25.4523 130.468L29.7352 129.67C26.9967 128.335 24.904 125.765 24.3031 122.54Z" clip-rule="evenodd"/><g filter="url(#filter0_d)"><path fill="#EEE" d="M232.896 31.2403H51.2975C49.1452 31.2403 47.4005 32.983 47.4005 35.1327V46.8101C47.4005 48.9598 49.1452 50.7025 51.2975 50.7025H232.896C235.048 50.7025 236.793 48.9598 236.793 46.8101V35.1327C236.793 32.983 235.048 31.2403 232.896 31.2403Z"/><mask id="mask0" width="190" height="114" x="47" y="31" mask-type="alpha" maskUnits="userSpaceOnUse"><path fill="#404040" d="M232.896 31.2403H51.2975C49.1452 31.2403 47.4005 32.983 47.4005 35.1327V141.007C47.4005 143.157 49.1452 144.9 51.2975 144.9H232.896C235.048 144.9 236.793 143.157 236.793 141.007V35.1327C236.793 32.983 235.048 31.2403 232.896 31.2403Z"/></mask><g mask="url(#mask0)"><path fill="#EEE" d="M239.91 42.1391H47.4005V150.349H239.91V42.1391Z"/></g></g><circle cx="188" cy="55" r="6" fill="#69DDC7"/><circle cx="91" cy="92" r="6" fill="#69DDC7"/><path fill="#69DDC7" d="M121 114L95.5 88L86.5 96L121 130L192.5 59L183.5 51L121 114Z"/><defs><filter id="filter0_d" width="229.392" height="153.66" x="29.401" y="15.24" color-interpolation-filters="sRGB" filterUnits="userSpaceOnUse"><feFlood flood-opacity="0" result="BackgroundImageFix"/><feColorMatrix in="SourceAlpha" type="matrix" values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 127 0"/><feOffset dx="2" dy="4"/><feGaussianBlur stdDeviation="10"/><feColorMatrix type="matrix" values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.25 0"/><feBlend in2="BackgroundImageFix" mode="normal" result="effect1_dropShadow"/><feBlend in="SourceGraphic" in2="effect1_dropShadow" mode="normal" result="shape"/></filter></defs></svg>
1
+ <svg xmlns="http://www.w3.org/2000/svg" width="282" height="173" fill="none" viewBox="0 0 282 173"><path fill="#000" fill-opacity=".05" fill-rule="evenodd" d="M16.4571 45.1637C11.0514 46.1711 7.48574 51.3699 8.49306 56.7756C9.50039 62.1814 14.6992 65.747 20.105 64.7397L27.5528 63.3518C25.4791 65.5835 24.4525 68.7347 25.0535 71.9596C26.0608 77.3653 31.2596 80.931 36.6654 79.9236L89.691 70.0427C89.7016 70.1067 89.7129 70.1708 89.7249 70.2349C90.3258 73.4598 92.4185 76.0298 95.1569 77.3647L91.9031 77.971C86.4974 78.9784 82.9318 84.1772 83.9391 89.583C84.9464 94.9887 90.1452 98.5543 95.551 97.547L250.098 68.7482C255.504 67.7409 259.069 62.5421 258.062 57.1363C257.461 53.9114 255.368 51.3414 252.63 50.0065L257.835 49.0366C263.241 48.0292 266.807 42.8304 265.799 37.4247C264.792 32.0189 259.593 28.4533 254.187 29.4606L161.492 46.7338C161.481 46.6697 161.47 46.6056 161.458 46.5415C160.857 43.3166 158.764 40.7466 156.026 39.4117L165.025 37.7347C170.431 36.7274 173.997 31.5286 172.989 26.1228C171.982 20.7171 166.783 17.1514 161.378 18.1588L16.4571 45.1637ZM24.3031 122.54C23.2958 117.134 26.8614 111.936 32.2672 110.928L190.856 81.3762C196.262 80.3688 201.461 83.9345 202.468 89.3402C203.476 94.746 199.91 99.9448 194.504 100.952L189.963 101.798C190.493 102.057 190.999 102.362 191.474 102.708L246.43 92.4677C251.835 91.4604 257.034 95.026 258.041 100.432C258.642 103.657 257.616 106.808 255.542 109.04L256.649 108.833C262.055 107.826 267.253 111.392 268.261 116.797C269.268 122.203 265.702 127.402 260.297 128.409L95.5591 159.107C90.1534 160.114 84.9545 156.549 83.9472 151.143C82.9399 145.737 86.5055 140.538 91.9113 139.531L103.94 137.29C103.41 137.031 102.904 136.726 102.429 136.38L29.1002 150.044C23.6944 151.051 18.4956 147.486 17.4882 142.08C16.4809 136.674 20.0465 131.475 25.4523 130.468L29.7352 129.67C26.9967 128.335 24.904 125.765 24.3031 122.54Z" clip-rule="evenodd"/><circle cx="188" cy="55" r="6" fill="#69DDC7"/><circle cx="91" cy="92" r="6" fill="#69DDC7"/><path fill="#69DDC7" d="M121 114L95.5 88L86.5 96L121 130L192.5 59L183.5 51L121 114Z"/></svg>
package/dist/index.d.ts CHANGED
@@ -4,6 +4,7 @@ import { Entity } from '@backstage/catalog-model';
4
4
  import * as _backstage_core_plugin_api from '@backstage/core-plugin-api';
5
5
  import { DiscoveryApi, IdentityApi, OAuthApi } from '@backstage/core-plugin-api';
6
6
  import { KubernetesRequestBody, ObjectsByEntityResponse } from '@backstage/plugin-kubernetes-common';
7
+ import { JsonObject } from '@backstage/types';
7
8
 
8
9
  declare const kubernetesPlugin: _backstage_core_plugin_api.BackstagePlugin<{
9
10
  entityContent: _backstage_core_plugin_api.RouteRef<undefined>;
@@ -60,13 +61,15 @@ declare class KubernetesAuthProviders implements KubernetesAuthProvidersApi {
60
61
  declare type FormatClusterLinkOptions = {
61
62
  dashboardUrl?: string;
62
63
  dashboardApp?: string;
64
+ dashboardParameters?: JsonObject;
63
65
  object: any;
64
66
  kind: string;
65
67
  };
66
68
  declare function formatClusterLink(options: FormatClusterLinkOptions): string | undefined;
67
69
 
68
70
  interface ClusterLinksFormatterOptions {
69
- dashboardUrl: URL;
71
+ dashboardUrl?: URL;
72
+ dashboardParameters?: JsonObject;
70
73
  object: any;
71
74
  kind: string;
72
75
  }
package/dist/index.esm.js CHANGED
@@ -11,7 +11,7 @@ import Close from '@material-ui/icons/Close';
11
11
  import OpenInNewIcon from '@material-ui/icons/OpenInNew';
12
12
  import { withStyles } from '@material-ui/core/styles';
13
13
  import jsYaml from 'js-yaml';
14
- import { useInterval } from 'react-use';
14
+ import useInterval from 'react-use/lib/useInterval';
15
15
  import cronstrue from 'cronstrue';
16
16
  import lodash from 'lodash';
17
17
  import PauseIcon from '@material-ui/icons/Pause';
@@ -40,7 +40,7 @@ class KubernetesBackendClient {
40
40
  }
41
41
  async postRequired(path, requestBody) {
42
42
  const url = `${await this.discoveryApi.getBaseUrl("kubernetes")}${path}`;
43
- const idToken = await this.identityApi.getIdToken();
43
+ const { token: idToken } = await this.identityApi.getCredentials();
44
44
  const response = await fetch(url, {
45
45
  method: "POST",
46
46
  headers: {
@@ -55,7 +55,7 @@ class KubernetesBackendClient {
55
55
  return await this.postRequired(`/services/${requestBody.entity.metadata.name}`, requestBody);
56
56
  }
57
57
  async getClusters() {
58
- const idToken = await this.identityApi.getIdToken();
58
+ const { token: idToken } = await this.identityApi.getCredentials();
59
59
  const url = `${await this.discoveryApi.getBaseUrl("kubernetes")}/clusters`;
60
60
  const response = await fetch(url, {
61
61
  method: "GET",
@@ -102,11 +102,18 @@ class AwsKubernetesAuthProvider {
102
102
  }
103
103
  }
104
104
 
105
+ class GoogleServiceAccountAuthProvider {
106
+ async decorateRequestBodyForAuth(requestBody) {
107
+ return requestBody;
108
+ }
109
+ }
110
+
105
111
  class KubernetesAuthProviders {
106
112
  constructor(options) {
107
113
  this.kubernetesAuthProviderMap = /* @__PURE__ */ new Map();
108
114
  this.kubernetesAuthProviderMap.set("google", new GoogleKubernetesAuthProvider(options.googleAuthApi));
109
115
  this.kubernetesAuthProviderMap.set("serviceAccount", new ServiceAccountKubernetesAuthProvider());
116
+ this.kubernetesAuthProviderMap.set("googleServiceAccount", new GoogleServiceAccountAuthProvider());
110
117
  this.kubernetesAuthProviderMap.set("aws", new AwsKubernetesAuthProvider());
111
118
  }
112
119
  async decorateRequestBodyForAuth(authProvider, requestBody) {
@@ -624,18 +631,22 @@ const ClusterContext = React__default.createContext({
624
631
  name: ""
625
632
  });
626
633
 
627
- const kindMappings$2 = {
634
+ const kindMappings$3 = {
628
635
  deployment: "deployment",
636
+ pod: "pod",
629
637
  ingress: "ingress",
630
638
  service: "service",
631
639
  horizontalpodautoscaler: "deployment"
632
640
  };
633
641
  function standardFormatter(options) {
634
642
  var _a, _b, _c, _d;
643
+ if (!options.dashboardUrl) {
644
+ throw new Error("standard dashboard requires a dashboardUrl option");
645
+ }
635
646
  const result = new URL(options.dashboardUrl.href);
636
647
  const name = encodeURIComponent((_b = (_a = options.object.metadata) == null ? void 0 : _a.name) != null ? _b : "");
637
648
  const namespace = encodeURIComponent((_d = (_c = options.object.metadata) == null ? void 0 : _c.namespace) != null ? _d : "");
638
- const validKind = kindMappings$2[options.kind.toLocaleLowerCase("en-US")];
649
+ const validKind = kindMappings$3[options.kind.toLocaleLowerCase("en-US")];
639
650
  if (!result.pathname.endsWith("/")) {
640
651
  result.pathname += "/";
641
652
  }
@@ -650,7 +661,7 @@ function standardFormatter(options) {
650
661
  return result;
651
662
  }
652
663
 
653
- const kindMappings$1 = {
664
+ const kindMappings$2 = {
654
665
  deployment: "apps.deployment",
655
666
  ingress: "networking.k8s.io.ingress",
656
667
  service: "service",
@@ -658,10 +669,13 @@ const kindMappings$1 = {
658
669
  };
659
670
  function rancherFormatter(options) {
660
671
  var _a, _b, _c, _d;
672
+ if (!options.dashboardUrl) {
673
+ throw new Error("Rancher dashboard requires a dashboardUrl option");
674
+ }
661
675
  const basePath = new URL(options.dashboardUrl.href);
662
676
  const name = encodeURIComponent((_b = (_a = options.object.metadata) == null ? void 0 : _a.name) != null ? _b : "");
663
677
  const namespace = encodeURIComponent((_d = (_c = options.object.metadata) == null ? void 0 : _c.namespace) != null ? _d : "");
664
- const validKind = kindMappings$1[options.kind.toLocaleLowerCase("en-US")];
678
+ const validKind = kindMappings$2[options.kind.toLocaleLowerCase("en-US")];
665
679
  if (!basePath.pathname.endsWith("/")) {
666
680
  basePath.pathname += "/";
667
681
  }
@@ -674,7 +688,7 @@ function rancherFormatter(options) {
674
688
  return new URL(path, basePath);
675
689
  }
676
690
 
677
- const kindMappings = {
691
+ const kindMappings$1 = {
678
692
  deployment: "deployments",
679
693
  ingress: "ingresses",
680
694
  service: "services",
@@ -683,10 +697,13 @@ const kindMappings = {
683
697
  };
684
698
  function openshiftFormatter(options) {
685
699
  var _a, _b, _c, _d;
700
+ if (!options.dashboardUrl) {
701
+ throw new Error("OpenShift dashboard requires a dashboardUrl option");
702
+ }
686
703
  const basePath = new URL(options.dashboardUrl.href);
687
704
  const name = encodeURIComponent((_b = (_a = options.object.metadata) == null ? void 0 : _a.name) != null ? _b : "");
688
705
  const namespace = encodeURIComponent((_d = (_c = options.object.metadata) == null ? void 0 : _c.namespace) != null ? _d : "");
689
- const validKind = kindMappings[options.kind.toLocaleLowerCase("en-US")];
706
+ const validKind = kindMappings$1[options.kind.toLocaleLowerCase("en-US")];
690
707
  if (!basePath.pathname.endsWith("/")) {
691
708
  basePath.pathname += "/";
692
709
  }
@@ -714,8 +731,45 @@ function eksFormatter(_options) {
714
731
  throw new Error("EKS formatter is not yet implemented. Please, contribute!");
715
732
  }
716
733
 
717
- function gkeFormatter(_options) {
718
- throw new Error("GKE formatter is not yet implemented. Please, contribute!");
734
+ const kindMappings = {
735
+ deployment: "deployment",
736
+ pod: "pod",
737
+ ingress: "ingress",
738
+ service: "service",
739
+ horizontalpodautoscaler: "deployment"
740
+ };
741
+ function gkeFormatter(options) {
742
+ var _a, _b, _c, _d;
743
+ if (!options.dashboardParameters) {
744
+ throw new Error("GKE dashboard requires a dashboardParameters option");
745
+ }
746
+ const args = options.dashboardParameters;
747
+ if (typeof args.projectId !== "string") {
748
+ throw new Error('GKE dashboard requires a "projectId" of type string in the dashboardParameters option');
749
+ }
750
+ if (typeof args.region !== "string") {
751
+ throw new Error('GKE dashboard requires a "region" of type string in the dashboardParameters option');
752
+ }
753
+ if (typeof args.clusterName !== "string") {
754
+ throw new Error('GKE dashboard requires a "clusterName" of type string in the dashboardParameters option');
755
+ }
756
+ const basePath = new URL("https://console.cloud.google.com/");
757
+ const region = encodeURIComponent(args.region);
758
+ const clusterName = encodeURIComponent(args.clusterName);
759
+ const name = encodeURIComponent((_b = (_a = options.object.metadata) == null ? void 0 : _a.name) != null ? _b : "");
760
+ const namespace = encodeURIComponent((_d = (_c = options.object.metadata) == null ? void 0 : _c.namespace) != null ? _d : "");
761
+ const validKind = kindMappings[options.kind.toLocaleLowerCase("en-US")];
762
+ let path = "";
763
+ if (namespace && name && validKind) {
764
+ const kindsWithDetails = ["ingress", "pod"];
765
+ const landingPage = kindsWithDetails.includes(validKind) ? "details" : "overview";
766
+ path = `kubernetes/${validKind}/${region}/${clusterName}/${namespace}/${name}/${landingPage}`;
767
+ } else {
768
+ path = `kubernetes/clusters/details/${region}/${clusterName}/details`;
769
+ }
770
+ const result = new URL(path, basePath);
771
+ result.searchParams.set("project", args.projectId);
772
+ return result;
719
773
  }
720
774
 
721
775
  const clusterLinksFormatters = {
@@ -729,10 +783,10 @@ const clusterLinksFormatters = {
729
783
  const defaultFormatterName = "standard";
730
784
 
731
785
  function formatClusterLink(options) {
732
- if (!options.dashboardUrl) {
786
+ if (!options.dashboardUrl && !options.dashboardParameters) {
733
787
  return void 0;
734
788
  }
735
- if (!options.object) {
789
+ if (options.dashboardUrl && !options.object) {
736
790
  return options.dashboardUrl;
737
791
  }
738
792
  const app = options.dashboardApp || defaultFormatterName;
@@ -741,7 +795,8 @@ function formatClusterLink(options) {
741
795
  throw new Error(`Could not find Kubernetes dashboard app named '${app}'`);
742
796
  }
743
797
  const url = formatter({
744
- dashboardUrl: new URL(options.dashboardUrl),
798
+ dashboardUrl: options.dashboardUrl ? new URL(options.dashboardUrl) : void 0,
799
+ dashboardParameters: options.dashboardParameters,
745
800
  object: options.object,
746
801
  kind: options.kind
747
802
  });
@@ -821,6 +876,7 @@ const KubernetesDrawerContent = ({
821
876
  const { clusterLink, errorMessage } = tryFormatClusterLink({
822
877
  dashboardUrl: cluster.dashboardUrl,
823
878
  dashboardApp: cluster.dashboardApp,
879
+ dashboardParameters: cluster.dashboardParameters,
824
880
  object,
825
881
  kind
826
882
  });