-
Notifications
You must be signed in to change notification settings - Fork 9
Refactor to remove legacyconfig object #163
Changes from 1 commit
f708a33
7d1bbdf
3e64e43
c613565
e51288a
3329943
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 |
---|---|---|
|
@@ -17,7 +17,6 @@ import ( | |
orchInf "github.com/atlassian/voyager/pkg/orchestration/informer" | ||
orchUpdater "github.com/atlassian/voyager/pkg/orchestration/updater" | ||
"github.com/atlassian/voyager/pkg/orchestration/wiring" | ||
"github.com/atlassian/voyager/pkg/orchestration/wiring/legacy" | ||
"github.com/atlassian/voyager/pkg/orchestration/wiring/wiringplugin" | ||
prom_util "github.com/atlassian/voyager/pkg/util/prometheus" | ||
"github.com/pkg/errors" | ||
|
@@ -30,9 +29,9 @@ import ( | |
) | ||
|
||
type ControllerConstructor struct { | ||
FlagConfigFile string | ||
GetLegacyConfigFunc func(voyager.Location) *legacy.Config | ||
Plugins map[voyager.ResourceType]wiringplugin.WiringPlugin | ||
FlagConfigFile string | ||
Plugins map[voyager.ResourceType]wiringplugin.WiringPlugin | ||
Tags wiring.TagGenerator | ||
} | ||
|
||
func (cc *ControllerConstructor) AddFlags(flagset ctrl.FlagSet) { | ||
|
@@ -88,14 +87,7 @@ func (cc *ControllerConstructor) New(config *ctrl.Config, cctx *ctrl.Context) (* | |
Plugins: cc.Plugins, | ||
ClusterLocation: opts.Location.ClusterLocation(), | ||
ClusterConfig: toClusterConfig(opts.Cluster), | ||
TagNames: wiring.TagNames{ | ||
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. Why this change? Seems unrelated to LegacyConfig. Could you split into multiple PRs please? 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. See the comment about introducing the tag generator. If the tags come from a function there's no need to make their keys come in via config. |
||
ServiceNameTag: opts.TagNames.ServiceName, | ||
BusinessUnitTag: opts.TagNames.BusinessUnit, | ||
ResourceOwnerTag: opts.TagNames.ResourceOwner, | ||
PlatformTag: opts.TagNames.Platform, | ||
EnvironmentTypeTag: opts.TagNames.EnvironmentType, | ||
}, | ||
GetLegacyConfigFunc: cc.GetLegacyConfigFunc, | ||
Tags: cc.Tags, | ||
} | ||
|
||
// Spec check | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,7 +13,7 @@ import ( | |
creator_v1 "github.com/atlassian/voyager/pkg/apis/creator/v1" | ||
"github.com/atlassian/voyager/pkg/creator/luigi" | ||
"github.com/atlassian/voyager/pkg/creator/ssam" | ||
ec2compute_common "github.com/atlassian/voyager/pkg/orchestration/wiring/ec2compute/common" | ||
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. This is also unrelated to LegacyConfig? separate PR please. |
||
ec2compute_v2 "github.com/atlassian/voyager/pkg/orchestration/wiring/ec2compute/v2" | ||
"github.com/atlassian/voyager/pkg/pagerduty" | ||
"github.com/atlassian/voyager/pkg/servicecentral" | ||
"github.com/atlassian/voyager/pkg/util" | ||
|
@@ -33,7 +33,7 @@ const ( | |
ServiceNameMinimumLength = 1 | ||
ServiceNameMaximumLength = 24 | ||
ServiceNameExpr = schema.ResourceNameSchemaPattern | ||
EC2ComputeNameMaximumLength = ec2compute_common.MaximumServiceNameLength | ||
EC2ComputeNameMaximumLength = ec2compute_v2.MaximumServiceNameLength | ||
) | ||
|
||
var ( | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,11 +34,16 @@ const ( | |
|
||
// All osb-aws-provider resources are 'almost' the same, differing only in the service/plan names, | ||
// what they need passed in the ServiceEnvironment. | ||
var ResourceTypes = map[voyager.ResourceType]wiringplugin.WiringPlugin{ | ||
DynamoDB: wiringutil.StatusAdapter(Resource(DynamoDB, DynamoDBName, DynamoDBClass, DynamoDBPlan, dynamoDbServiceEnvironment, dynamoDbShapes).WireUp), | ||
S3: wiringutil.StatusAdapter(Resource(S3, S3Name, S3Class, S3Plan, s3ServiceEnvironment, s3Shapes).WireUp), | ||
Cfn: wiringutil.StatusAdapter(Resource(Cfn, CfnName, CfnClass, CfnPlan, CfnServiceEnvironment, cfnShapes).WireUp), | ||
} | ||
var ( | ||
emptyVPC = func(location voyager.Location) *oap.VPCEnvironment { | ||
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. How do you construct non-empty VPC and make it environment-specific without LegacyConfig? 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. We're passing a function type based on public types. I won't be using know authowire plugins in the close repo. 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. I'm sorry, I don't understand this English :( 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. It's not. Follow the code in the orchestration main in this PR. 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. I'm confused. If you want to construct plugins dynamically, these static plugin variables simply should not exist, at least in the non-test package. 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. I agree with Nail's point. Would be better to move the not-really-ready-to-use instances of plugins (and other "stubby" stuff) into some testing package 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. Think these comments are now outdated. |
||
return oap.ExampleVPC(location.Label, location.Region) | ||
} | ||
DynamoDBPlugin = wiringutil.StatusAdapter(Resource(DynamoDB, DynamoDBName, DynamoDBClass, DynamoDBPlan, dynamoDbServiceEnvironment, dynamoDbShapes, emptyVPC).WireUp) | ||
|
||
S3Plugin = wiringutil.StatusAdapter(Resource(S3, S3Name, S3Class, S3Plan, s3ServiceEnvironment, s3Shapes, emptyVPC).WireUp) | ||
|
||
CfnPlugin = wiringutil.StatusAdapter(Resource(Cfn, CfnName, CfnClass, CfnPlan, CfnServiceEnvironment, cfnShapes, emptyVPC).WireUp) | ||
) | ||
|
||
func cfnShapes(resource *orch_v1.StateResource, smithResource *smith_v1.Resource, _ *wiringplugin.WiringContext) ([]wiringplugin.Shape, bool /* externalErr */, bool /* retriableErr */, error) { | ||
templateName, external, retriable, err := oap.TemplateName(resource.Spec) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -195,13 +195,26 @@ func constructComputeParameters(origSpec *runtime.RawExtension, iamRoleRef, iamI | |
} | ||
|
||
func New() *WiringPlugin { | ||
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. The members of this struct and it's use are the only changes to this class, everything else is just moving code from the extra package. |
||
return &WiringPlugin{} | ||
return &WiringPlugin{ | ||
DeveloperRole: func(_ voyager.Location) []string { | ||
return []string{"arn:aws:iam::123456789012:role/micros-server-iam-MicrosServer-ABC"} //example | ||
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. Legacy config is a major issue for manual or experimental testing of autowiring functions. You have to use the internal build to access this data. Tthe way shapes hold things together also practically requires all the functions be in this repo so you can find and reference them simply. 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. I don't disagree, it would be nice to replace LegacyConfig with resource-specific configuration. 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. There is a ticket to make autowiring functions accept configuration into their constructor. Even with legacy config completely gone we'd still need this functionality. 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. That's exactly what I meant, if it wasn't clear :) 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. We build the list of plugins. All of their "constructors" are accessible. There is not requirement to use known plugins object. 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. Then the first trivial change would be to pass LegacyConfig to plugin constructors which use information from it, and remove it from the context? This would be a global LegacyConfig I suppose (not location-specific), but that's ok. It could also be a function providing a LegacyConfig for a given location. This should be a relatively simple isolated change, easy to review. 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. Actually, we already have this function: https://github.com/atlassian/voyager/blob/master/pkg/orchestration/wiring/entangler.go#L161-L173 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. Look at the main function for orchestration. It takes registry.KnownWiringPlugins as an arg of type map[voyager.ResourceType]wiringplugin.WiringPlugin. There is no reason this needs to be the same map inside the close source repo. 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. Also notice that master of this repo currently stubs legacy config with a nothing but empty strings. |
||
}, | ||
ManagedPolicies: func(_ voyager.Location) []string { | ||
return []string{"arn:aws:iam::123456789012:policy/SOX-DENY-IAM-CREATE-DELETE", "arn:aws:iam::123456789012:policy/micros-iam-DefaultServicePolicy-ABC"} // example | ||
}, | ||
VPC: func(location voyager.Location) *oap.VPCEnvironment { | ||
return oap.ExampleVPC(location.Label, location.Region) | ||
}, | ||
} | ||
} | ||
|
||
type WiringPlugin struct { | ||
DeveloperRole func(location voyager.Location) []string | ||
ManagedPolicies func(location voyager.Location) []string | ||
VPC func(location voyager.Location) *oap.VPCEnvironment | ||
} | ||
|
||
func WireUp(stateResource *orch_v1.StateResource, context *wiringplugin.WiringContext) wiringplugin.WiringResult { | ||
func (p *WiringPlugin) WireUp(stateResource *orch_v1.StateResource, context *wiringplugin.WiringContext) wiringplugin.WiringResult { | ||
if stateResource.Type != ResourceType { | ||
return &wiringplugin.WiringResultFailure{ | ||
Error: errors.Errorf("invalid resource type: %q", stateResource.Type), | ||
|
@@ -221,7 +234,7 @@ func WireUp(stateResource *orch_v1.StateResource, context *wiringplugin.WiringCo | |
} | ||
} | ||
|
||
return wireUp(userInput.Service.ID, ec2ComputePlanName, stateResource, context, constructComputeParameters) | ||
return p.wireUp(userInput.Service.ID, ec2ComputePlanName, stateResource, context, constructComputeParameters) | ||
} | ||
|
||
func generateSecretResource(compute voyager.ResourceName, envVars map[string]string, dependencyReferences []smith_v1.Reference) (smith_v1.Resource, error) { | ||
|
@@ -264,7 +277,7 @@ func calculateServiceName(serviceName voyager.ServiceName, resourceName voyager. | |
return microsServiceName, nil | ||
} | ||
|
||
func wireUp(microServiceNameInSpec, ec2ComputePlanName string, stateResource *orch_v1.StateResource, context *wiringplugin.WiringContext, constructComputeParameters ConstructComputeParametersFunction) wiringplugin.WiringResult { | ||
func (p *WiringPlugin) wireUp(microServiceNameInSpec, ec2ComputePlanName string, stateResource *orch_v1.StateResource, context *wiringplugin.WiringContext, constructComputeParameters ConstructComputeParametersFunction) wiringplugin.WiringResult { | ||
dependencies := context.Dependencies | ||
|
||
if err := compute.ValidateASAPDependencies(context); err != nil { | ||
|
@@ -387,8 +400,8 @@ func wireUp(microServiceNameInSpec, ec2ComputePlanName string, stateResource *or | |
bindingResources = append(bindingResources, secretResource) | ||
} | ||
|
||
assumeRoles := []string{context.StateContext.LegacyConfig.DeployerRole} | ||
managedPolicies := context.StateContext.LegacyConfig.ManagedPolicies | ||
assumeRoles := p.DeveloperRole(context.StateContext.Location) | ||
managedPolicies := p.ManagedPolicies(context.StateContext.Location) | ||
|
||
// The only things that generate IamSnippets are the things that have the correct shape | ||
iamPluginInstanceSmithResource, err := iam.PluginServiceInstance( | ||
|
@@ -400,6 +413,7 @@ func wireUp(microServiceNameInSpec, ec2ComputePlanName string, stateResource *or | |
context, | ||
managedPolicies, | ||
assumeRoles, | ||
p.VPC(context.StateContext.Location), | ||
) | ||
if err != nil { | ||
return &wiringplugin.WiringResultFailure{ | ||
|
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.
The real problem, I think, is that autowiring functions at the moment are not configurable (they are all hardcoded), and the only way to pass configuration is via context and orchestration controller constructor
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.
What about moving the plugins out of wiring/registry? We can pass them as parameters into the constructor for orchestration controller.
This matches up with what @amckague has done for the example tag generator, and it's what we sort of do for smith too. We're going to want to split the wiring out of this repo anyway.