Merge pull request #8216 from brexhq/k8s-api-version-overrides
K8s api version overrides
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@backstage/plugin-kubernetes-backend': patch
|
||||
---
|
||||
|
||||
Added apiVersionOverrides config to allow for specifying api versions to use for kubernetes objects
|
||||
@@ -219,6 +219,26 @@ The custom resource's apiVersion.
|
||||
|
||||
The plural representing the custom resource.
|
||||
|
||||
### `apiVersionOverrides` (optional)
|
||||
|
||||
Overrides for the API versions used to make requests for the corresponding
|
||||
objects. If using a legacy Kubernetes version, you may use this config to
|
||||
override the default API versions to ones that are supported by your cluster.
|
||||
|
||||
Example:
|
||||
|
||||
```yaml
|
||||
---
|
||||
kubernetes:
|
||||
apiVersionOverrides:
|
||||
cronjobs: 'v1beta1'
|
||||
```
|
||||
|
||||
For more information on which API versions are supported by your cluster, please
|
||||
view the Kubernetes API docs for your Kubernetes version (e.g.
|
||||
[API Groups for v1.22](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.22/#-strong-api-groups-strong-)
|
||||
)
|
||||
|
||||
### Role Based Access Control
|
||||
|
||||
The current RBAC permissions required are read-only cluster wide, for the
|
||||
|
||||
+18
@@ -63,5 +63,23 @@ export interface Config {
|
||||
apiVersion: string;
|
||||
plural: string;
|
||||
}>;
|
||||
|
||||
/**
|
||||
* (Optional) API Version Overrides
|
||||
* If set, the specified api version will be used to make requests for the corresponding object.
|
||||
* If running a legacy Kubernetes version, you may use this to override the default api versions
|
||||
* that are not supported in your cluster.
|
||||
*/
|
||||
apiVersionOverrides?: {
|
||||
pods?: string;
|
||||
services?: string;
|
||||
configmaps?: string;
|
||||
deployments?: string;
|
||||
replicasets?: string;
|
||||
horizontalpodautoscalers?: string;
|
||||
cronjobs?: string;
|
||||
jobs?: string;
|
||||
ingresses?: string;
|
||||
} & { [pluralKind: string]: string };
|
||||
};
|
||||
}
|
||||
|
||||
@@ -243,6 +243,10 @@ export class KubernetesBuilder {
|
||||
'kubernetes.objectTypes',
|
||||
) as KubernetesObjectTypes[];
|
||||
|
||||
const apiVersionOverrides = this.env.config.getOptionalConfig(
|
||||
'kubernetes.apiVersionOverrides',
|
||||
);
|
||||
|
||||
let objectTypesToFetch;
|
||||
|
||||
if (objectTypesToFetchStrings) {
|
||||
@@ -250,6 +254,17 @@ export class KubernetesBuilder {
|
||||
objectTypesToFetchStrings.includes(obj.objectType),
|
||||
);
|
||||
}
|
||||
|
||||
if (apiVersionOverrides) {
|
||||
objectTypesToFetch = objectTypesToFetch ?? DEFAULT_OBJECTS;
|
||||
|
||||
for (const obj of objectTypesToFetch) {
|
||||
if (apiVersionOverrides.has(obj.objectType)) {
|
||||
obj.apiVersion = apiVersionOverrides.getString(obj.objectType);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return objectTypesToFetch;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user