-
Notifications
You must be signed in to change notification settings - Fork 808
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
feat(moniker): Use moniker in TrafficGuard. #1727
Changes from 5 commits
56804f3
53a21da
51d2dff
b8e76fd
b2360e3
08e5a5f
2ab69cf
579f27c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,7 +47,7 @@ public abstract class AbstractBulkServerGroupTask extends AbstractCloudProviderA | |
@Autowired | ||
protected KatoService katoService; | ||
|
||
abstract void validateClusterStatus(Map<String, Object> operation); | ||
abstract void validateClusterStatus(Map<String, Object> operation, Moniker moniker); | ||
|
||
abstract String getClouddriverOperation(); | ||
|
||
|
@@ -104,8 +104,9 @@ public TaskResult execute(Stage stage) { | |
targetServerGroups.forEach( targetServerGroup -> { | ||
Map<String , Map> tmp = new HashMap<>(); | ||
Map operation = targetServerGroup.toClouddriverOperationPayload(request.getCredentials()); | ||
|
||
validateClusterStatus(operation); | ||
Moniker moniker = targetServerGroup.getMoniker() == null ? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Slightly cleaner alternative to a somewhat ugly multiline ternary.
|
||
MonikerHelper.friggaToMoniker(targetServerGroup.getName()) : targetServerGroup.getMoniker(); | ||
validateClusterStatus(operation, moniker); | ||
tmp.put(getClouddriverOperation(), operation); | ||
operations.add(tmp); | ||
}); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,7 @@ | |
|
||
package com.netflix.spinnaker.orca.clouddriver.tasks.servergroup | ||
|
||
import com.netflix.spinnaker.moniker.Moniker | ||
import com.netflix.spinnaker.orca.ExecutionStatus | ||
import com.netflix.spinnaker.orca.RetryableTask | ||
import com.netflix.spinnaker.orca.TaskResult | ||
|
@@ -25,6 +26,7 @@ import com.netflix.spinnaker.orca.clouddriver.pipeline.servergroup.support.Locat | |
import com.netflix.spinnaker.orca.clouddriver.pipeline.servergroup.support.TargetServerGroup | ||
import com.netflix.spinnaker.orca.clouddriver.pipeline.servergroup.support.TargetServerGroupResolver | ||
import com.netflix.spinnaker.orca.clouddriver.tasks.AbstractCloudProviderAwareTask | ||
import com.netflix.spinnaker.orca.clouddriver.utils.MonikerHelper | ||
import com.netflix.spinnaker.orca.pipeline.model.Stage | ||
import org.springframework.beans.factory.annotation.Autowired | ||
|
||
|
@@ -47,7 +49,7 @@ abstract class AbstractServerGroupTask extends AbstractCloudProviderAwareTask im | |
false | ||
} | ||
|
||
protected void validateClusterStatus(Map operation) {} | ||
protected void validateClusterStatus(Map operation, Moniker moniker) {} | ||
|
||
abstract String getServerGroupAction() | ||
|
||
|
@@ -58,9 +60,9 @@ abstract class AbstractServerGroupTask extends AbstractCloudProviderAwareTask im | |
TaskResult execute(Stage stage) { | ||
String cloudProvider = getCloudProvider(stage) | ||
String account = getCredentials(stage) | ||
|
||
def operation = convert(stage) | ||
validateClusterStatus(operation) | ||
Moniker moniker = convertMoniker(stage) | ||
validateClusterStatus(operation, moniker) | ||
if (!operation) { | ||
// nothing to do but succeed | ||
return new TaskResult(ExecutionStatus.SUCCEEDED) | ||
|
@@ -108,6 +110,17 @@ abstract class AbstractServerGroupTask extends AbstractCloudProviderAwareTask im | |
operation | ||
} | ||
|
||
Moniker convertMoniker(Stage stage) { | ||
if (TargetServerGroup.isDynamicallyBound(stage)) { | ||
TargetServerGroup tsg = TargetServerGroupResolver.fromPreviousStage(stage); | ||
return tsg.getMoniker() == null ? MonikerHelper.friggaToMoniker(tsg.getName()) : tsg.getMoniker(); | ||
} else { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. don't need the and since this is groovy, we can do:
|
||
String serverGroupName = (String) stage.context.serverGroupName; | ||
String asgName = (String) stage.context.asgName; | ||
return MonikerHelper.monikerFromStage(stage, serverGroupName == null ? asgName : serverGroupName); | ||
} | ||
} | ||
|
||
/** | ||
* @return a Map of location -> server group name | ||
*/ | ||
|
@@ -138,5 +151,4 @@ abstract class AbstractServerGroupTask extends AbstractCloudProviderAwareTask im | |
operation.namespace ? new Location(Type.NAMESPACE, operation.namespace) : | ||
null | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,8 @@ | |
|
||
import com.netflix.frigga.Names; | ||
import com.netflix.spinnaker.moniker.Moniker; | ||
import com.netflix.spinnaker.orca.clouddriver.pipeline.servergroup.support.TargetServerGroup; | ||
import com.netflix.spinnaker.orca.clouddriver.pipeline.servergroup.support.TargetServerGroupResolver; | ||
import com.netflix.spinnaker.orca.pipeline.model.Stage; | ||
import org.springframework.stereotype.Component; | ||
|
||
|
@@ -27,6 +29,7 @@ | |
*/ | ||
@Component | ||
public class MonikerHelper { | ||
|
||
public String getAppNameFromStage(Stage stage, String fallbackFriggaName) { | ||
Names names = Names.parseName(fallbackFriggaName); | ||
Moniker moniker = monikerFromStage(stage); | ||
|
@@ -58,4 +61,21 @@ static public Moniker monikerFromStage(Stage stage) { | |
return null; | ||
} | ||
} | ||
|
||
static public Moniker monikerFromStage(Stage stage, String fallbackFriggaName) { | ||
Moniker moniker = monikerFromStage(stage); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Q: what happens when you have a stage that's dealing with potentially > 1 server group or cluster?
The rollback stages are a current example with > 1 server group specified. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thats a great point. I just tried a rollback and noticed this is what is sent from Deck to Orca:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So in the case of TrafficGuard, the moniker:
would be passed through. In TrafficGuard itself only There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ajordens Do you know an example of a stage that uses multiple clusters? |
||
return moniker == null ? friggaToMoniker(fallbackFriggaName) : moniker; | ||
} | ||
|
||
static public Moniker friggaToMoniker(String friggaName) { | ||
Names names = Names.parseName(friggaName); | ||
return Moniker.builder() | ||
.app(names.getApp()) | ||
.stack(names.getStack()) | ||
.detail(names.getDetail()) | ||
.cluster(names.getCluster()) | ||
.sequence(names.getSequence()) | ||
.build(); | ||
} | ||
|
||
} |
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.
Should inject an
ObjectMapper
into the constructor (it'll be autowired) vs explicitly creating one here.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.
Since TargetServerGroup is not a bean, I'm not quite sure how to do what you are asking. I pulled it out and made it
final static
for now.