@@ -466,11 +466,9 @@ func (c *Client) DeployWorkload(
466
466
return "" , 0 , fmt .Errorf ("failed to create external networks: %v" , err )
467
467
}
468
468
469
+ networkIsolation := false
469
470
if isolateNetwork {
470
- // Add a label to the MCP server indicating network isolation.
471
- // This allows other methods to determine whether it needs to care
472
- // about ingress/egress/dns containers.
473
- lb .AddNetworkIsolationLabel (labels )
471
+ networkIsolation = true
474
472
475
473
internalNetworkLabels := map [string ]string {}
476
474
lb .AddNetworkLabels (internalNetworkLabels , networkName )
@@ -516,6 +514,11 @@ func (c *Client) DeployWorkload(
516
514
return "" , 0 , fmt .Errorf ("failed to generate port bindings: %v" , err )
517
515
}
518
516
517
+ // Add a label to the MCP server indicating network isolation.
518
+ // This allows other methods to determine whether it needs to care
519
+ // about ingress/egress/dns containers.
520
+ lb .AddNetworkIsolationLabel (labels , networkIsolation )
521
+
519
522
containerId , err := c .createMcpContainer (
520
523
ctx ,
521
524
name ,
@@ -639,15 +642,12 @@ func (c *Client) StopWorkload(ctx context.Context, workloadID string) error {
639
642
}
640
643
641
644
// If network isolation is not enabled, then there is nothing else to do.
642
- // TODO: This check is currently commented out because we need to ensure
643
- // that workloads created by older versions of ToolHive get cleaned up
644
- // properly. Once we are confident that all workloads with network isolation
645
- // have the label set, we can uncomment this check.
646
- /*
647
- if !lb.HasNetworkIsolation(info.Labels) {
648
- return nil
649
- }
650
- */
645
+ // NOTE: This check treats all workloads created before the introduction of
646
+ // this label as having network isolation enabled. This is to ensure that they
647
+ // get cleaned up properly during stop/rm.
648
+ if ! lb .HasNetworkIsolation (info .Labels ) {
649
+ return nil
650
+ }
651
651
652
652
// remove / from container name
653
653
containerName := strings .TrimPrefix (info .Name , "/" )
@@ -668,11 +668,11 @@ func (c *Client) StopWorkload(ctx context.Context, workloadID string) error {
668
668
func (c * Client ) stopProxyContainer (ctx context.Context , containerName string , timeoutSeconds int ) {
669
669
containerId , err := c .findExistingContainer (ctx , containerName )
670
670
if err != nil {
671
- logger .Warnf ("Failed to find internal container %s: %v" , containerName , err )
671
+ logger .Debugf ("Failed to find internal container %s: %v" , containerName , err )
672
672
} else {
673
673
err = c .client .ContainerStop (ctx , containerId , container.StopOptions {Timeout : & timeoutSeconds })
674
674
if err != nil {
675
- logger .Warnf ("Failed to stop internal container %s: %v" , containerName , err )
675
+ logger .Debugf ("Failed to stop internal container %s: %v" , containerName , err )
676
676
}
677
677
}
678
678
}
@@ -729,16 +729,13 @@ func (c *Client) RemoveWorkload(ctx context.Context, workloadID string) error {
729
729
}
730
730
731
731
// If network isolation is not enabled, then there is nothing else to do.
732
- // TODO: This check is currently commented out because we need to ensure
733
- // that workloads created by older versions of ToolHive get cleaned up
734
- // properly. Once we are confident that all workloads with network isolation
735
- // have the label set, we can uncomment this check.
736
- // If network isolation is not enabled, then there is nothing else to do.
737
- /*
738
- if containerResponse.Config != nil && !lb.HasNetworkIsolation(containerResponse.Config.Labels) {
739
- return nil
740
- }
741
- */
732
+ // NOTE: This check treats all workloads created before the introduction of
733
+ // this label as having network isolation enabled. This is to ensure that they
734
+ // get cleaned up properly during stop/rm. There may be some spurious warnings
735
+ // from the following code, but they can be ignored.
736
+ if containerResponse .Config != nil && ! lb .HasNetworkIsolation (containerResponse .Config .Labels ) {
737
+ return nil
738
+ }
742
739
743
740
// remove egress, ingress, and dns containers
744
741
suffixes := []string {"egress" , "ingress" , "dns" }
@@ -747,7 +744,7 @@ func (c *Client) RemoveWorkload(ctx context.Context, workloadID string) error {
747
744
containerName := fmt .Sprintf ("%s-%s" , containerName , suffix )
748
745
containerId , err := c .findExistingContainer (ctx , containerName )
749
746
if err != nil {
750
- logger .Warnf ("Failed to find %s container %s: %v" , suffix , containerName , err )
747
+ logger .Debugf ("Failed to find %s container %s: %v" , suffix , containerName , err )
751
748
continue
752
749
}
753
750
if containerId == "" {
0 commit comments