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

Adding state attribute to the HNSEndpoint struct to support hyperv #2177

Merged
merged 1 commit into from
Jun 24, 2024

Conversation

ritikaguptams
Copy link
Contributor

@ritikaguptams ritikaguptams commented Jun 18, 2024

The struct HNSEndpoint is used by CNIs like calico to validate the state of an endpoint. In order to support Hyperv containers on k8s we need to expose the State attribute. This attribute can be used by CNIs to determine the state of the endpoint.

HNS API versions:
Hcsshim supports both APIS v1 and v2 via the HCN folder (documented way) or via hns files in the root which expose internal/hns apis

CodeFlow:
Calico::endpoint_mgr.go::RefreshHnsEndpointCache --> hns.HNSListEndpointRequest() which lands at hcsshim/hnsendpoint.go which calls into the internal HNS package at /hcsshim/internal/hns which runs a get call into HNS OS code.

@ritikaguptams ritikaguptams force-pushed the hypervNetwork branch 3 times, most recently from 8984865 to 4403a04 Compare June 20, 2024 20:34
…ntainers for k8s

Signed-off-by: ritikaguptams <85255050+ritikaguptams@users.noreply.github.com>

Adding stringer for usage and CI/CD

Signed-off-by: ritikaguptams <85255050+ritikaguptams@users.noreply.github.com>

Fixing build errors

Signed-off-by: ritikaguptams <85255050+ritikaguptams@users.noreply.github.com>

Ignore linting for files generated by Stringer

Signed-off-by: ritikaguptams <85255050+ritikaguptams@users.noreply.github.com>

Trying to fix CI go gen

Signed-off-by: ritikaguptams <85255050+ritikaguptams@users.noreply.github.com>

Removing extra step to fix CI go gen

Signed-off-by: ritikaguptams <85255050+ritikaguptams@users.noreply.github.com>

go gen CI fix try 2

Signed-off-by: ritikaguptams <85255050+ritikaguptams@users.noreply.github.com>

Skip autogenerated file from linting

Signed-off-by: ritikaguptams <85255050+ritikaguptams@users.noreply.github.com>

Fixing linting

Signed-off-by: ritikaguptams <85255050+ritikaguptams@users.noreply.github.com>

Fixing linting

Signed-off-by: ritikaguptams <85255050+ritikaguptams@users.noreply.github.com>

Removing stringer to avoid increasing package bloat for hcsshim

Signed-off-by: ritikaguptams <85255050+ritikaguptams@users.noreply.github.com>

cleanup

Signed-off-by: ritikaguptams <85255050+ritikaguptams@users.noreply.github.com>

Adding comment for future HNS v2 change

Signed-off-by: ritikaguptams <85255050+ritikaguptams@users.noreply.github.com>

Fix linting

Signed-off-by: ritikaguptams <85255050+ritikaguptams@users.noreply.github.com>
@ritikaguptams
Copy link
Contributor Author

cc @jsturtevant @sbangari

// EndpointState const
// The lifecycle of an Endpoint goes through created, attached, AttachedSharing - endpoint is being shared with other containers,
// detached, after being attached, degraded and finally destroyed.
// Note: This attribute is used by calico to define stale containers and is dependent on HNS v1 api, if we move to HNS v2 api we will need
Copy link
Contributor

Choose a reason for hiding this comment

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

@sbangari @ritikaguptams Is there a way to add a unit test that fails when we moved to v2? I think this would be really important to have to avoid any regression in the future.

Copy link
Contributor

Choose a reason for hiding this comment

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

Is it that only Calico that is using the v1 endpoint? There are tests in https://github.com/microsoft/hcsshim/blob/main/hcn/hcnendpoint_test.go but I think that is v2 api?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi @kiashok,

My understanding is hcsshim uses exposes both v1 and v2 apis via the hcsshim/hcn code, which is documented and has testing support. Our codeflow currently is a minor change to add an attribute in an v1 api call. Underlying understanding is calico currently runs on HNS v1 support. We should not have any breaking changes from this change as users on v2 api call would use Hcshim/hcn/hcnendpoint ListEndpointsofNetwork instead of Hcshim/hnsendpoint HNSListEndpointRequest

The comments in there are only for documentation purpose i.e. if ever calico moves to v2 they would have to redo their logic on stale endpoints, which uses 'State' as that attribute is not exposed via HNS v2 api currently.

Copy link
Contributor

Choose a reason for hiding this comment

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

sounds good, thanks for the detailed response. We should open an issue on Calico project so they know they are using HNS v1 api's in some places.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will do!

Copy link
Contributor

@jsturtevant jsturtevant left a comment

Choose a reason for hiding this comment

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

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants