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: Refactor KubeObject class #1967

Merged
merged 4 commits into from
Oct 24, 2024
Merged

frontend: Refactor KubeObject class #1967

merged 4 commits into from
Oct 24, 2024

Conversation

sniok
Copy link
Contributor

@sniok sniok commented May 9, 2024

This PR refactors KubeObject class and how we define different Kubernetes resources.

Resource classes will now:

  • extend KubeObject class instead of makeKubeObject function
    KubeObject currently resolves to any. So everywhere KubeObject was used there's no type safety.
  • not have objectName
  • have kind apiName isNamespaced and apiVersion fields
  • not have to define apiFactory, it will automatically made based on the class fields

This PR makes KubeObject a class that's available outside of makeKubeObject (deprecated) function

Summary of the changes

// Before
class Pod extends makeKubeObject<KubePod>('Pod') {
  static apiEndpoint = apiFactoryWithNamespace('', 'v1', 'pods');
}

// After
class Pod extends KubeObject<KubePod> {
  static kind = 'Pod';
  static apiName = 'pods';
  static apiVersion = 'v1';
  static isNamespaced = true;
}

This PR also fixes all the type errors that were surfaced by KubeObject not resolving to any

@sniok sniok force-pushed the kube-type branch 3 times, most recently from 621b07d to 0653be0 Compare May 10, 2024 12:33
@sniok sniok force-pushed the kube-type branch 7 times, most recently from 7a5511b to 62a9c07 Compare August 2, 2024 11:46
@sniok sniok marked this pull request as ready for review August 2, 2024 11:46
@sniok sniok changed the title WIP frontend: Fix KubeObject type and all its uses Refactor KubeObject class Aug 2, 2024
@sniok
Copy link
Contributor Author

sniok commented Aug 2, 2024

This is ready for review.
While there are a lot of files changed, most of them (with some exceptions) are only type changes. I've tried not to change any implementation to fix type errors (unless it was obvious like a typo)

@sniok sniok requested review from illume and joaquimrocha August 2, 2024 11:53
@sniok sniok changed the title Refactor KubeObject class frontend: Refactor KubeObject class Aug 2, 2024
@sniok sniok force-pushed the kube-type branch 13 times, most recently from 1dea316 to a6d2baf Compare August 6, 2024 11:27
Copy link
Collaborator

@joaquimrocha joaquimrocha left a comment

Choose a reason for hiding this comment

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

Left a comment about something I found. Also needs rebasing now.

frontend/src/lib/k8s/KubeObject.ts Outdated Show resolved Hide resolved
@sniok sniok force-pushed the kube-type branch 8 times, most recently from 0b1f1fc to 28733b1 Compare October 23, 2024 13:19
@sniok
Copy link
Contributor Author

sniok commented Oct 23, 2024

I've managed to refactor types a bit to avoid CodeQL hanging (it's not as pretty but works)
Opened an issue in codeql repo, but for now this is okay

@sniok sniok marked this pull request as ready for review October 24, 2024 09:04
@dosubot dosubot bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Oct 24, 2024
@sniok sniok requested a review from joaquimrocha October 24, 2024 09:04
@sniok sniok force-pushed the kube-type branch 3 times, most recently from 6a1e482 to 92b9596 Compare October 24, 2024 14:02
sniok added 4 commits October 24, 2024 18:07
Signed-off-by: Oleksandr Dubenko <oldubenko@microsoft.com>
Signed-off-by: Oleksandr Dubenko <oldubenko@microsoft.com>
Signed-off-by: Oleksandr Dubenko <oldubenko@microsoft.com>
…formation

Signed-off-by: Oleksandr Dubenko <oldubenko@microsoft.com>
@joaquimrocha joaquimrocha merged commit bf8c8f0 into main Oct 24, 2024
16 of 18 checks passed
@joaquimrocha joaquimrocha deleted the kube-type branch October 24, 2024 17:11
@sniok sniok mentioned this pull request Oct 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size:L This PR changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants