github.com/cilium/cilium@v1.16.2/pkg/alibabacloud/utils/utils.go (about)

     1  // SPDX-License-Identifier: Apache-2.0
     2  // Copyright Authors of Cilium
     3  
     4  package utils
     5  
     6  import (
     7  	"strconv"
     8  
     9  	"github.com/sirupsen/logrus"
    10  )
    11  
    12  const eniIndexTagKey = "cilium-eni-index"
    13  
    14  // GetENIIndexFromTags get ENI index from tags
    15  func GetENIIndexFromTags(tags map[string]string) int {
    16  	v, ok := tags[eniIndexTagKey]
    17  	if !ok {
    18  		return 0
    19  	}
    20  	index, err := strconv.Atoi(v)
    21  	if err != nil {
    22  		logrus.WithError(err).Warning("Unable to retrieve index from ENI")
    23  	}
    24  	return index
    25  }
    26  
    27  // FillTagWithENIIndex set the index to tags
    28  func FillTagWithENIIndex(tags map[string]string, index int) map[string]string {
    29  	tags[eniIndexTagKey] = strconv.Itoa(index)
    30  	return tags
    31  }