-
Notifications
You must be signed in to change notification settings - Fork 58
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Issue #3534: Tag compute resources according to the tool's metadata #3544
Conversation
… initial API part
… delete tags method
… remove instance tags during pipeline stop
… support --custom_tags for nodeup
… support --custom_tags for reassign
… attach tags with disk
… tag ebs volumes when reassign
… supported for aws provider only
… support tags for lustre
client.deleteTags(new DeleteTagsRequest() | ||
.withResources(resourcesIds) | ||
.withTags(tags.stream() | ||
.map(Tag::new) | ||
.collect(Collectors.toList()))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's extract deleteTags
method similarly to how createTags
is extracted.
final Optional<PipelineRun> run = optionalRun.isPresent() ? optionalRun : pipelineRunManager.findRun(runId); | ||
if (!run.isPresent()) { | ||
return Collections.emptyMap(); | ||
} | ||
return metadataManager.prepareCustomInstanceTags(run.get()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can use more optional-friendly implementation here.
final Optional<PipelineRun> run = optionalRun.isPresent() ? optionalRun : pipelineRunManager.findRun(runId); | |
if (!run.isPresent()) { | |
return Collections.emptyMap(); | |
} | |
return metadataManager.prepareCustomInstanceTags(run.get()); | |
return optionalRun.map(Optional::of) | |
.orElseGet(() -> pipelineRunManager.findRun(runId)) | |
.map(metadataManager::prepareCustomInstanceTags) | |
.orElseGet(Collections::emptyMap); |
final Set<String> instanceTagsKeys = new HashSet<>(Arrays.asList(preferenceManager.findPreference( | ||
SystemPreferences.CLUSTER_INSTANCE_ALLOWED_CUSTOM_TAGS) | ||
.filter(StringUtils::isNotBlank) | ||
.map(value -> value.split(",")) | ||
.orElse(Strings.EMPTY_ARRAY))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can use Stream API here.
final Set<String> instanceTagsKeys = new HashSet<>(Arrays.asList(preferenceManager.findPreference( | |
SystemPreferences.CLUSTER_INSTANCE_ALLOWED_CUSTOM_TAGS) | |
.filter(StringUtils::isNotBlank) | |
.map(value -> value.split(",")) | |
.orElse(Strings.EMPTY_ARRAY))); | |
final Set<String> instanceTagsKeys = preferenceManager.findPreference( | |
SystemPreferences.CLUSTER_INSTANCE_ALLOWED_CUSTOM_TAGS) | |
.filter(StringUtils::isNotBlank) | |
.map(value -> value.split(",")) | |
.map(Arrays::stream) | |
.orElseGet(Stream::empty) | |
.filter(StringUtils::isNotBlank) | |
.collect(Collectors.toSet()); |
final Map<String, PipeConfValue> metadataData = MapUtils.emptyIfNull(Objects.isNull(toolMetadata) | ||
? null | ||
: toolMetadata.getData()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Optionals are perfect for such a situation.
final Map<String, PipeConfValue> metadataData = MapUtils.emptyIfNull(Objects.isNull(toolMetadata) | |
? null | |
: toolMetadata.getData()); | |
final Map<String, PipeConfValue> metadataData = Optional.ofNullable(toolMetadata) | |
.map(MetadataEntry::getData) | |
.orElseGet(Collections::emptyMap); |
final Map<String, String> customTags = resolveCommonCustomInstanceTags(run); | ||
return resolveInstanceTagsFromMetadata(run.getDockerImage(), customTags); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would suggest using a simpler approach for collecting tags from various sources.
final Map<String, String> customTags = resolveCommonCustomInstanceTags(run); | |
return resolveInstanceTagsFromMetadata(run.getDockerImage(), customTags); | |
final Map<String, String> implicitTags = resolveCommonCustomInstanceTags(run); | |
final Map<String, String> explicitTags = resolveInstanceTagsFromMetadata(run); | |
return CommonUtils.mergeMaps(implicitTags, explicitTags); |
* - run_id - Integer ID of a run | ||
* - owner - Username of a run owner | ||
*/ | ||
public enum CommonCustomInstanceTagsTypes { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the name of the class is too confusing. It's both common and custom. Can we just call it CommonInstanceTagType
? I think that for the most part of the code in this pull request there is no actual need in having custom in name.
… cleanup namings
… comma separated list refactor
The current PR provides implementation for issue #3534
The following changes were added:
cluster.instances.tags
. This preference supportstool
/run_id
/owner
keys only.cluster.instances.allowed.tags
. This preferences allows to specify comma-separated list of string values. If tool's metadata key exactly matches the value from this list the corresponding metadata (a key-value pair) shall be added to compute resources tags.Name
value is not allowed.nodeup
andreassign_node
scripts support new--tags
option. This option accepts a list of <tag_name>=<tag_value> string values. If this list provided the corresponding tags shall be added to instances and ebs volumes.NOTE: all changes implemented for
AWS
provider only.