Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

frontend: Introduce kind, apiVersion, apiName fields for all KubeObjects #2399

Closed
wants to merge 2 commits into from

Conversation

sniok
Copy link
Contributor

@sniok sniok commented Oct 7, 2024

Fixes #2384

frontend/src/lib/k8s/cluster.ts Outdated Show resolved Hide resolved
frontend/src/lib/k8s/cluster.ts Show resolved Hide resolved
frontend/src/lib/k8s/cluster.ts Show resolved Hide resolved
frontend/src/lib/k8s/cluster.ts Show resolved Hide resolved
Comment on lines 6 to 11
static kind = 'ClusterRole';
static apiName = 'clusterroles';
static apiVersion = 'rbac.authorization.k8s.io/v1';
static isNamespaced = false;

static apiEndpoint = apiFactory('rbac.authorization.k8s.io', 'v1', 'clusterroles');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This means we are repeating the apiEndpoint's args with the apiVersion and isNamespaced vars.
Would it work and be backward compat if we had apiEndpoint be a getter by default? So we could return apiFactory/WithNamespace using the apiVersion and isNamespaced vars.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

apiEndpoint still contains methods like get,post,put that are still used, so we can't replace it with a getter yet. I think this duplication is okay for now, after v2 migration we can get rid of apiEndpoint completely

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My point is that we need the apiEndpoint for now but we can generate it ourselves by having a getter. Let me try adding a fixup commit.

frontend/src/lib/k8s/index.ts Outdated Show resolved Hide resolved
frontend/src/lib/k8s/cluster.ts Outdated Show resolved Hide resolved
@sniok
Copy link
Contributor Author

sniok commented Oct 8, 2024

So we can get rid of objectName altogether, since route names are case insensitive we can use apiName and kind for lists and details routes. With exceptions for Endpoints and CRDs.

This keeps all the same values (although casing will be consistent) and gets rid of all the other overrides.

ResourceClasses keys are manually converted to title case, so kind will be fine, with the exception for the Endpoint .

Before (objectName, objectName+s and overrides)
ResourceClassesKey className(=objectName) pluralName(=objectName+s) detailsRoute(=objectName) listRoute(=objectName+s)
ClusterRole ClusterRole clusterroles ClusterRole* ClusterRoles
ClusterRoleBinding ClusterRoleBinding clusterrolebindings ClusterRoleBinding ClusterRoleBindings
ConfigMap configMap configmaps configMap configMaps
CustomResourceDefinition CustomResourceDefinition customresourcedefinitions crd crds
CronJob CronJob cronjobs CronJob CronJobs
DaemonSet DaemonSet daemonsets DaemonSet DaemonSets
Deployment Deployment deployments Deployment Deployments
Endpoint endpoint endpoints endpoint endpoints
LimitRange LimitRange limitranges LimitRange LimitRanges
Lease Lease leases Lease Leases
ResourceQuota resourceQuota resourcequotas resourceQuota resourceQuotas
HorizontalPodAutoscaler horizontalPodAutoscaler horizontalpodautoscalers horizontalPodAutoscaler horizontalPodAutoscalers
PodDisruptionBudget podDisruptionBudget poddisruptionbudgets podDisruptionBudget podDisruptionBudgets
PriorityClass priorityClass priorityclasses priorityClass priorityclasses
Ingress ingress ingresses ingress ingresses
IngressClass ingressClass ingressclasses ingressClass ingressclasses
Job Job jobs Job Jobs
Namespace namespace namespaces namespace namespaces
NetworkPolicy NetworkPolicy networkpolicies NetworkPolicy NetworkPolicys
Node node nodes node nodes
PersistentVolume persistentVolume persistentvolumes persistentVolume persistentVolumes
PersistentVolumeClaim persistentVolumeClaim persistentvolumeclaims persistentVolumeClaim persistentVolumeClaims
Pod Pod pods Pod Pods
ReplicaSet ReplicaSet replicasets ReplicaSet ReplicaSets
Role role roles role roles
RoleBinding roleBinding rolebindings roleBinding roleBindings
RuntimeClass RuntimeClass runtimeclasses RuntimeClass runtimeclasses
Secret secret secrets secret secrets
Service service services service services
ServiceAccount serviceAccount serviceaccounts serviceAccount serviceAccounts
StatefulSet StatefulSet statefulsets StatefulSet StatefulSets
StorageClass storageClass storageclasses storageClass storageClasses
After (kind and apiName)
ResourceClassesKey className (= kind) pluralName (= apiName) detailsRoute (= kind) listRoute (= apiName)
ClusterRole ClusterRole clusterroles ClusterRole clusterroles
ClusterRoleBinding ClusterRoleBinding clusterrolebindings ClusterRoleBinding clusterrolebindings
ConfigMap ConfigMap configmaps ConfigMap configmaps
CustomResourceDefinition CustomResourceDefinition customresourcedefinitions crd crds
CronJob CronJob cronjobs CronJob cronjobs
DaemonSet DaemonSet daemonsets DaemonSet daemonsets
Deployment Deployment deployments Deployment deployments
Endpoint endpoint* endpoints endpoint* endpoints
LimitRange LimitRange limitranges LimitRange limitranges
Lease Lease leases Lease leases
ResourceQuota ResourceQuota resourcequotas ResourceQuota resourcequotas
HorizontalPodAutoscaler HorizontalPodAutoscaler horizontalpodautoscalers HorizontalPodAutoscaler horizontalpodautoscalers
PodDisruptionBudget PodDisruptionBudget poddisruptionbudgets PodDisruptionBudget poddisruptionbudgets
PriorityClass PriorityClass priorityclasses PriorityClass priorityclasses
Ingress Ingress ingresses Ingress ingresses
IngressClass IngressClass ingressclasses IngressClass ingressclasses
Job Job jobs Job jobs
Namespace Namespace namespaces Namespace namespaces
NetworkPolicy NetworkPolicy networkpolicies NetworkPolicy networkpolicies
Node Node nodes Node nodes
PersistentVolume PersistentVolume persistentvolumes PersistentVolume persistentvolumes
PersistentVolumeClaim PersistentVolumeClaim persistentvolumeclaims PersistentVolumeClaim persistentvolumeclaims
Pod Pod pods Pod pods
ReplicaSet ReplicaSet replicasets ReplicaSet replicasets
Role Role roles Role roles
RoleBinding RoleBinding rolebindings RoleBinding rolebindings
RuntimeClass RuntimeClass runtimeclasses RuntimeClass runtimeclasses
Secret Secret secrets Secret secrets
Service Service services Service services
ServiceAccount ServiceAccount serviceaccounts ServiceAccount serviceaccounts
StatefulSet StatefulSet statefulsets StatefulSet statefulsets
StorageClass StorageClass storageclasses StorageClass storageClasses

@sniok sniok force-pushed the object-name branch 2 times, most recently from 289b29a to 94dcb6b Compare October 8, 2024 15:18
Signed-off-by: Oleksandr Dubenko <oldubenko@microsoft.com>
@sniok sniok requested a review from joaquimrocha October 9, 2024 11:23
@sniok sniok marked this pull request as ready for review October 9, 2024 11:23
@dosubot dosubot bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Oct 9, 2024
Copy link
Contributor

@skoeva skoeva left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this refactor! cleans things up well

@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Oct 10, 2024
…formation

Signed-off-by: Oleksandr Dubenko <oldubenko@microsoft.com>
@sniok
Copy link
Contributor Author

sniok commented Oct 15, 2024

this change will be part of #1967 PR

@sniok sniok closed this Oct 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lgtm This PR has been approved by a maintainer size:L This PR changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add a way to get the resource kind from its resource class
3 participants