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

feat: allow specify the context to be added #962

Merged
merged 1 commit into from
Jun 1, 2024

Conversation

cr7258
Copy link
Contributor

@cr7258 cr7258 commented May 28, 2024

Description

Implement: #952 (comment)
Add a new parameter --context to specify the context to be added when running kubecm add or merge command.

Test

Prepare two kubeconfig.

./kubecm list --config kubeconfig1
+------------+-------------+-------------+----------+-------------------------+--------------+
|   CURRENT  |     NAME    |   CLUSTER   |   USER   |          SERVER         |   Namespace  |
+============+=============+=============+==========+=========================+==============+
|      *     |   context1  |   cluster1  |   user1  |   https://example1.com  |    default   |
+------------+-------------+-------------+----------+-------------------------+--------------+

./kubecm list --config kubeconfig2
+------------+-------------+-------------+----------+-------------------------+----------------+
|   CURRENT  |     NAME    |   CLUSTER   |   USER   |          SERVER         |    Namespace   |
+============+=============+=============+==========+=========================+================+
|      *     |   context2  |   cluster2  |   user2  |   https://example2.com  |   kube-system  |
+------------+-------------+-------------+----------+-------------------------+----------------+
|            |   context3  |   cluster3  |   user3  |   https://example3.com  |     default    |
+------------+-------------+-------------+----------+-------------------------+----------------+
|            |   context4  |   cluster4  |   user4  |   https://example4.com  |     default    |
+------------+-------------+-------------+----------+-------------------------+----------------+

Specify context2 and context3 to be added.

./kubecm add --config kubeconfig1 -f kubeconfig2 --context context2,context3

# result
+------------+-------------+-------------+----------+-------------------------+----------------+
|   CURRENT  |     NAME    |   CLUSTER   |   USER   |          SERVER         |    Namespace   |
+============+=============+=============+==========+=========================+================+
|      *     |   context1  |   cluster1  |   user1  |   https://example1.com  |     default    |
+------------+-------------+-------------+----------+-------------------------+----------------+
|            |   context2  |   cluster2  |   user2  |   https://example2.com  |   kube-system  |
+------------+-------------+-------------+----------+-------------------------+----------------+
|            |   context3  |   cluster3  |   user3  |   https://example3.com  |     default    |
+------------+-------------+-------------+----------+-------------------------+----------------+

Specify context1 and context2 to be merged.

./kubecm merge kubeconfig1 kubeconfig2 --context context1,context2

# result
+------------+-------------+-------------+----------+-------------------------+----------------+
|   CURRENT  |     NAME    |   CLUSTER   |   USER   |          SERVER         |    Namespace   |
+============+=============+=============+==========+=========================+================+
|            |   context1  |   cluster1  |   user1  |   https://example1.com  |     default    |
+------------+-------------+-------------+----------+-------------------------+----------------+
|            |   context2  |   cluster2  |   user2  |   https://example2.com  |   kube-system  |
+------------+-------------+-------------+----------+-------------------------+----------------+

Specify the contexts to be added after overwriting the name with the context template.

./kubecm add --config kubeconfig1 -f kubeconfig2 --context cluster2-user2,cluster3-user3 --context-template cluster,user

# result
+------------+-------------------+-------------+----------+-------------------------+----------------+
|   CURRENT  |        NAME       |   CLUSTER   |   USER   |          SERVER         |    Namespace   |
+============+===================+=============+==========+=========================+================+
|            |   cluster2-user2  |   cluster2  |   user2  |   https://example2.com  |   kube-system  |
+------------+-------------------+-------------+----------+-------------------------+----------------+
|            |   cluster3-user3  |   cluster3  |   user3  |   https://example3.com  |     default    |
+------------+-------------------+-------------+----------+-------------------------+----------------+
|      *     |      context1     |   cluster1  |   user1  |   https://example1.com  |     default    |
+------------+-------------------+-------------+----------+-------------------------+----------------+

Related Issue

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • [] Documentation update (changes only affecting documentation)

Checklist

  • I have tested my changes locally and ensured they are functioning properly. Please run the make build and make test commands.
  • I have added/updated unit or e2e tests to cover my changes.
  • I have updated the relevant documentation. If you change commands or arguments, run make doc-gen to generate new documentation.

@the-label-bot the-label-bot bot added kind/feature ategorizes issue or PR as related to a new feature. size/L size/L labels May 28, 2024
Copy link

the-label-bot bot commented May 28, 2024

The Label Bot has predicted the following:

Category Value Confidence Applied Label
Kind feature 0.800 ✔️
Kind L 0.855 ✔️

Copy link

codecov bot commented May 28, 2024

Codecov Report

Attention: Patch coverage is 18.75000% with 26 lines in your changes are missing coverage. Please review.

Project coverage is 19.68%. Comparing base (67886bf) to head (b38e4f3).
Report is 1 commits behind head on master.

Files Patch % Lines
cmd/add.go 37.50% 9 Missing and 1 partial ⚠️
cmd/cloud_add.go 0.00% 10 Missing ⚠️
cmd/merge.go 0.00% 6 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #962      +/-   ##
==========================================
+ Coverage   19.65%   19.68%   +0.03%     
==========================================
  Files          21       21              
  Lines        2122     2134      +12     
==========================================
+ Hits          417      420       +3     
- Misses       1661     1670       +9     
  Partials       44       44              
Flag Coverage Δ
unittests 19.68% <18.75%> (+0.03%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@sunny0826 sunny0826 self-requested a review May 31, 2024 03:30
Copy link
Owner

@sunny0826 sunny0826 left a comment

Choose a reason for hiding this comment

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

LGTM
Thank you for your valuable contribution to this project! Your work is greatly appreciated. 🎆

@sunny0826 sunny0826 merged commit 13fbf30 into sunny0826:master Jun 1, 2024
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/feature ategorizes issue or PR as related to a new feature. size/L size/L
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants