Skip to content

Commit

Permalink
Fix comments
Browse files Browse the repository at this point in the history
  • Loading branch information
samjkon committed Nov 1, 2023
1 parent 287230f commit 8cf80a1
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 15 deletions.
3 changes: 3 additions & 0 deletions ecs-agent/metrics/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,7 @@ const (
GetNetworkConfigurationByTaskMetricName = dbClientMetricNamespace + ".GetNetworkConfigurationByTask"
SaveNetworkNamespaceMetricName = dbClientMetricNamespace + ".SaveNetworkNamespace"
GetNetworkNamespaceMetricName = dbClientMetricNamespace + ".GetNetworkNamespace"

networkBuilderNamespace = "NetworkBuilder"
BuildNetworkNamespaceMetricName = networkBuilderNamespace + ".BuildNetworkNamespace"
)
13 changes: 13 additions & 0 deletions ecs-agent/netlib/data/network_client.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License"). You may
// not use this file except in compliance with the License. A copy of the
// License is located at
//
// http://aws.amazon.com/apache2.0/
//
// or in the "license" file accompanying this file. This file is distributed
// on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
// express or implied. See the License for the specific language governing
// permissions and limitations under the License.

package data

import (
Expand Down
35 changes: 20 additions & 15 deletions ecs-agent/netlib/network_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"github.com/aws/amazon-ecs-agent/ecs-agent/acs/model/ecsacs"
"github.com/aws/amazon-ecs-agent/ecs-agent/api/ecs/model/ecs"
"github.com/aws/amazon-ecs-agent/ecs-agent/data"
"github.com/aws/amazon-ecs-agent/ecs-agent/logger"
"github.com/aws/amazon-ecs-agent/ecs-agent/metrics"
netlibdata "github.com/aws/amazon-ecs-agent/ecs-agent/netlib/data"
"github.com/aws/amazon-ecs-agent/ecs-agent/netlib/model/status"
Expand All @@ -27,7 +28,6 @@ import (
"github.com/aws/amazon-ecs-agent/ecs-agent/volume"

"github.com/pkg/errors"
"github.com/sirupsen/logrus"
)

type NetworkBuilder interface {
Expand Down Expand Up @@ -78,16 +78,19 @@ func (nb *networkBuilder) Start(
mode string, taskID string,
netNS *tasknetworkconfig.NetworkNamespace,
) error {
netNS.Mutex.Lock()
defer netNS.Mutex.Unlock()

logrus.WithFields(logrus.Fields{
logFields := map[string]interface{}{
"NetworkMode": mode,
"NetNSName": netNS.Name,
"NetNSPath": netNS.Path,
"AppMeshEnabled": netNS.AppMeshConfig != nil,
"ServiceConnectEnabled": netNS.ServiceConnectConfig != nil,
}).Info("Starting network namespace setup")
}
metricEntry := nb.metricsFactory.New(metrics.BuildNetworkNamespaceMetricName).WithFields(logFields)

netNS.Mutex.Lock()
defer netNS.Mutex.Unlock()

logger.Info("Starting network namespace setup", logFields)

var err error
switch mode {
Expand All @@ -97,6 +100,8 @@ func (nb *networkBuilder) Start(
err = errors.New("invalid network mode: " + mode)
}

metricEntry.Done(err)

return err
}

Expand All @@ -117,14 +122,14 @@ func (nb *networkBuilder) startAWSVPC(ctx context.Context, taskID string, netNS
if netNS.KnownState == status.NetworkNone &&
netNS.DesiredState == status.NetworkReadyPull {

logrus.Debugf("Creating netns: %s", netNS.Path)
logger.Debug("Creating netns: " + netNS.Path)
// Create network namespace on the host.
err := nb.platformAPI.CreateNetNS(netNS.Path)
if err != nil {
return err
}

logrus.Debug("Creating DNS config files")
logger.Debug("Creating DNS config files")

// Create necessary DNS config files for the netns.
err = nb.platformAPI.CreateDNSConfig(taskID, netNS)
Expand All @@ -137,16 +142,16 @@ func (nb *networkBuilder) startAWSVPC(ctx context.Context, taskID string, netNS
// Depending on the type of interfaces in the netns, there maybe operations
// to execute when the netns desired status is READY_PULL and READY.
for _, iface := range netNS.NetworkInterfaces {
logger := logrus.WithFields(logrus.Fields{
logFields := logger.Fields{
"Interface": iface,
"NetNSName": netNS.Name,
})
}
if iface.KnownStatus == netNS.DesiredState {
logger.Debug("Interface already in desired state")
continue
}

logger.Debug("Configuring interface")
logger.Debug("Configuring interface", logFields)
iface.DesiredStatus = netNS.DesiredState

err := nb.platformAPI.ConfigureInterface(ctx, netNS.Path, iface)
Expand All @@ -160,9 +165,9 @@ func (nb *networkBuilder) startAWSVPC(ctx context.Context, taskID string, netNS
if netNS.KnownState == status.NetworkReadyPull &&
netNS.DesiredState == status.NetworkReady {
if netNS.AppMeshConfig != nil {
logrus.WithFields(logrus.Fields{
logger.Debug("Configuring AppMesh", logger.Fields{
"AppMeshConfig": netNS.AppMeshConfig,
}).Debug("Configuring AppMesh")
})

err := nb.platformAPI.ConfigureAppMesh(ctx, netNS.Path, netNS.AppMeshConfig)
if err != nil {
Expand All @@ -171,9 +176,9 @@ func (nb *networkBuilder) startAWSVPC(ctx context.Context, taskID string, netNS
}

if netNS.ServiceConnectConfig != nil {
logrus.WithFields(logrus.Fields{
logger.Debug("Configuring ServiceConnect", logger.Fields{
"ServiceConnectConfig": netNS.ServiceConnectConfig,
}).Debug("Configuring ServiceConnect")
})

err := nb.platformAPI.ConfigureServiceConnect(
ctx, netNS.Path, netNS.GetPrimaryInterface(), netNS.ServiceConnectConfig)
Expand Down
3 changes: 3 additions & 0 deletions ecs-agent/netlib/platform/cniconf_linux.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
//go:build !windows
// +build !windows

// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License"). You may
Expand Down
13 changes: 13 additions & 0 deletions ecs-agent/netlib/platform/common.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License"). You may
// not use this file except in compliance with the License. A copy of the
// License is located at
//
// http://aws.amazon.com/apache2.0/
//
// or in the "license" file accompanying this file. This file is distributed
// on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
// express or implied. See the License for the specific language governing
// permissions and limitations under the License.

package platform

import (
Expand Down

0 comments on commit 8cf80a1

Please sign in to comment.