github.com/juju/juju@v0.0.0-20240430160146-1752b71fcf00/environs/tags/tags.go (about)

     1  // Copyright 2015 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package tags
     5  
     6  import "github.com/juju/names/v5"
     7  
     8  const (
     9  	// JujuTagPrefix is the prefix for Juju-managed tags.
    10  	JujuTagPrefix = "juju-"
    11  
    12  	// JujuModel is the tag name used for identifying the
    13  	// Juju model a resource is part of.
    14  	JujuModel = JujuTagPrefix + "model-uuid"
    15  
    16  	// JujuController is the tag name used for identifying the
    17  	// Juju controller that manages a resource.
    18  	JujuController = JujuTagPrefix + "controller-uuid"
    19  
    20  	// JujuIsController is the tag name used for determining
    21  	// whether a machine instance is a controller or not.
    22  	JujuIsController = JujuTagPrefix + "is-controller"
    23  
    24  	// JujuUnitsDeployed is the tag name used for identifying
    25  	// the units deployed to a machine instance. The value is
    26  	// a space-separated list of the unit names.
    27  	JujuUnitsDeployed = JujuTagPrefix + "units-deployed"
    28  
    29  	// JujuStorageInstance is the tag name used for identifying
    30  	// the Juju storage instance that an IaaS storage resource
    31  	// is assigned to.
    32  	JujuStorageInstance = JujuTagPrefix + "storage-instance"
    33  
    34  	// JujuStorageOwner is the tag name used for identifying
    35  	// the application or unit that owns the Juju storage instance
    36  	// that an IaaS storage resource is assigned to.
    37  	JujuStorageOwner = JujuTagPrefix + "storage-owner"
    38  
    39  	// JujuMachine is the tag name used for identifying
    40  	// the model and machine id corresponding to the
    41  	// provisioned machine instance.
    42  	JujuMachine = JujuTagPrefix + "machine-id"
    43  )
    44  
    45  // ResourceTagger is an interface that can provide resource tags.
    46  type ResourceTagger interface {
    47  	// ResourceTags returns a set of resource tags, and a
    48  	// flag indicating whether or not any resource tags are
    49  	// available.
    50  	ResourceTags() (map[string]string, bool)
    51  }
    52  
    53  // ResourceTags returns tags to set on an infrastructure resource
    54  // for the specified Juju environment.
    55  func ResourceTags(modelTag names.ModelTag, controllerTag names.ControllerTag, taggers ...ResourceTagger) map[string]string {
    56  	allTags := make(map[string]string)
    57  	for _, tagger := range taggers {
    58  		tags, ok := tagger.ResourceTags()
    59  		if !ok {
    60  			continue
    61  		}
    62  		for k, v := range tags {
    63  			allTags[k] = v
    64  		}
    65  	}
    66  	allTags[JujuModel] = modelTag.Id()
    67  	allTags[JujuController] = controllerTag.Id()
    68  	return allTags
    69  }