-
Notifications
You must be signed in to change notification settings - Fork 79
Implement Support for LKE Enterprise #521
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
from linode_api4.groups import Group | ||
from linode_api4.objects import TieredKubeVersion | ||
|
||
|
||
class LKETierGroup(Group): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a new pattern since the LKE tier path is the first of its kind. Let me know if you have any feedback! |
||
""" | ||
Encapsulates methods related to a specific LKE tier. This | ||
should not be instantiated on its own, but should instead be used through | ||
an instance of :any:`LinodeClient`:: | ||
client = LinodeClient(token) | ||
instances = client.lke.tier("standard") # use the LKETierGroup | ||
This group contains all features beneath the `/lke/tiers/{tier}` group in the API v4. | ||
""" | ||
|
||
def __init__(self, client: "LinodeClient", tier: str): | ||
super().__init__(client) | ||
self.tier = tier | ||
|
||
def versions(self, *filters): | ||
""" | ||
Returns a paginated list of versions for this tier matching the given filters. | ||
API Documentation: Not Yet Available | ||
:param filters: Any number of filters to apply to this query. | ||
See :doc:`Filtering Collections</linode_api4/objects/filtering>` | ||
for more details on filtering. | ||
:returns: A paginated list of kube versions that match the query. | ||
:rtype: PaginatedList of TieredKubeVersion | ||
""" | ||
|
||
return self.client._get_and_filter( | ||
TieredKubeVersion, | ||
endpoint=f"/lke/tiers/{self.tier}/versions", | ||
parent_id=self.tier, | ||
*filters, | ||
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,7 @@ | |
Region, | ||
Type, | ||
) | ||
from linode_api4.objects.base import _flatten_request_body_recursive | ||
from linode_api4.util import drop_null_keys | ||
|
||
|
||
|
@@ -49,6 +50,26 @@ class KubeVersion(Base): | |
} | ||
|
||
|
||
class TieredKubeVersion(DerivedBase): | ||
""" | ||
A TieredKubeVersion is a version of Kubernetes that is specific to a certain LKE tier. | ||
|
||
NOTE: LKE tiers may not currently be available to all users. | ||
|
||
API Documentation: https://techdocs.akamai.com/linode-api/reference/get-lke-version | ||
""" | ||
|
||
api_endpoint = "/lke/tiers/{tier}/versions/{id}" | ||
parent_id_name = "tier" | ||
id_attribute = "id" | ||
derived_url_path = "versions" | ||
|
||
properties = { | ||
"id": Property(identifier=True), | ||
"tier": Property(identifier=True), | ||
} | ||
|
||
|
||
@dataclass | ||
class LKENodePoolTaint(JSONObject): | ||
""" | ||
|
@@ -154,6 +175,8 @@ class LKENodePool(DerivedBase): | |
An LKE Node Pool describes a pool of Linode Instances that exist within an | ||
LKE Cluster. | ||
|
||
NOTE: The k8s_version and update_strategy fields are only available for LKE Enterprise clusters. | ||
|
||
API Documentation: https://techdocs.akamai.com/linode-api/reference/get-lke-node-pool | ||
""" | ||
|
||
|
@@ -175,6 +198,12 @@ class LKENodePool(DerivedBase): | |
"tags": Property(mutable=True, unordered=True), | ||
"labels": Property(mutable=True), | ||
"taints": Property(mutable=True), | ||
# Enterprise-specific properties | ||
# Ideally we would use slug_relationship=TieredKubeVersion here, but | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Any ideas on workarounds for this? |
||
# it isn't possible without an extra request because the tier is not | ||
# directly exposed in the node pool response. | ||
"k8s_version": Property(mutable=True), | ||
"update_strategy": Property(mutable=True), | ||
} | ||
|
||
def _parse_raw_node( | ||
|
@@ -255,6 +284,7 @@ class LKECluster(Base): | |
"pools": Property(derived_class=LKENodePool), | ||
"control_plane": Property(mutable=True), | ||
"apl_enabled": Property(), | ||
"tier": Property(), | ||
} | ||
|
||
def invalidate(self): | ||
|
@@ -385,6 +415,10 @@ def node_pool_create( | |
node_count: int, | ||
labels: Optional[Dict[str, str]] = None, | ||
taints: List[Union[LKENodePoolTaint, Dict[str, Any]]] = None, | ||
k8s_version: Optional[ | ||
Union[str, KubeVersion, TieredKubeVersion] | ||
] = None, | ||
update_strategy: Optional[str] = None, | ||
**kwargs, | ||
): | ||
""" | ||
|
@@ -399,7 +433,13 @@ def node_pool_create( | |
:param labels: A dict mapping labels to their values to apply to this pool. | ||
:type labels: Dict[str, str] | ||
:param taints: A list of taints to apply to this pool. | ||
:type taints: List of :any:`LKENodePoolTaint` or dict | ||
:type taints: List of :any:`LKENodePoolTaint` or dict. | ||
:param k8s_version: The Kubernetes version to use for this pool. | ||
NOTE: This field is specific to enterprise clusters. | ||
:type k8s_version: str, KubeVersion, or TieredKubeVersion | ||
:param update_strategy: The strategy to use when updating this node pool. | ||
NOTE: This field is specific to enterprise clusters. | ||
:type update_strategy: str | ||
:param kwargs: Any other arguments to pass to the API. See the API docs | ||
for possible values. | ||
|
||
|
@@ -409,6 +449,10 @@ def node_pool_create( | |
params = { | ||
"type": node_type, | ||
"count": node_count, | ||
"labels": labels, | ||
"taints": taints, | ||
"k8s_version": k8s_version, | ||
"update_strategy": update_strategy, | ||
} | ||
|
||
if labels is not None: | ||
|
@@ -420,7 +464,9 @@ def node_pool_create( | |
params.update(kwargs) | ||
|
||
result = self._client.post( | ||
"{}/pools".format(LKECluster.api_endpoint), model=self, data=params | ||
"{}/pools".format(LKECluster.api_endpoint), | ||
model=self, | ||
data=drop_null_keys(_flatten_request_body_recursive(params)), | ||
) | ||
self.invalidate() | ||
|
||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"id": 18881, | ||
"status": "ready", | ||
"created": "2021-02-10T23:54:21", | ||
"updated": "2021-02-10T23:54:21", | ||
"label": "example-cluster-2", | ||
"region": "ap-west", | ||
"k8s_version": "1.31.1+lke1", | ||
"tier": "enterprise", | ||
"tags": [], | ||
"control_plane": { | ||
"high_availability": true | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"id": 789, | ||
"type": "g6-standard-2", | ||
"count": 3, | ||
"nodes": [], | ||
"disks": [], | ||
"autoscaler": { | ||
"enabled": false, | ||
"min": 3, | ||
"max": 3 | ||
}, | ||
"labels": {}, | ||
"taints": [], | ||
"tags": [], | ||
"disk_encryption": "enabled", | ||
"k8s_version": "1.31.1+lke1", | ||
"update_strategy": "rolling_update" | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"data": [ | ||
{ | ||
"id": "1.32", | ||
"tier": "standard" | ||
}, | ||
{ | ||
"id": "1.31", | ||
"tier": "standard" | ||
}, | ||
{ | ||
"id": "1.30", | ||
"tier": "standard" | ||
} | ||
], | ||
"page": 1, | ||
"pages": 1, | ||
"results": 3 | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.