From a0122a7723958322306b850753bb60909e5e7d0f Mon Sep 17 00:00:00 2001 From: ritikaguptams <85255050+ritikaguptams@users.noreply.github.com> Date: Tue, 18 Jun 2024 12:40:06 -0700 Subject: [PATCH] Adding state attribute to the HNSEndpoint struct to support hyperv containers 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> --- internal/hns/hnsendpoint.go | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/internal/hns/hnsendpoint.go b/internal/hns/hnsendpoint.go index 593664419d..6238e103be 100644 --- a/internal/hns/hnsendpoint.go +++ b/internal/hns/hnsendpoint.go @@ -10,6 +10,28 @@ import ( "github.com/sirupsen/logrus" ) +// EndpointState represents the states of an HNS Endpoint lifecycle. +type EndpointState uint16 + +// 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 +// to update the current calico code and cordinate the change with calico. Reach out to Microsoft to facilate the change via HNS. +const ( + Uninitialized EndpointState = iota + Created EndpointState = 1 + Attached EndpointState = 2 + AttachedSharing EndpointState = 3 + Detached EndpointState = 4 + Degraded EndpointState = 5 + Destroyed EndpointState = 6 +) + +func (es EndpointState) String() string { + return [...]string{"Uninitialized", "Attached", "AttachedSharing", "Detached", "Degraded", "Destroyed"}[es] +} + // HNSEndpoint represents a network endpoint in HNS type HNSEndpoint struct { Id string `json:"ID,omitempty"` @@ -34,6 +56,7 @@ type HNSEndpoint struct { Namespace *Namespace `json:",omitempty"` EncapOverhead uint16 `json:",omitempty"` SharedContainers []string `json:",omitempty"` + State EndpointState `json:",omitempty"` } // SystemType represents the type of the system on which actions are done