-
Notifications
You must be signed in to change notification settings - Fork 9
Refactor to remove legacyconfig object #163
Changes from 4 commits
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 |
---|---|---|
|
@@ -5,15 +5,17 @@ import ( | |
"flag" | ||
"math/rand" | ||
"os" | ||
"strings" | ||
"time" | ||
|
||
"github.com/atlassian/ctrl" | ||
ctrlApp "github.com/atlassian/ctrl/app" | ||
"github.com/atlassian/voyager" | ||
"github.com/atlassian/voyager/cmd" | ||
"github.com/atlassian/voyager/pkg/orchestration/wiring/legacy" | ||
orch_meta "github.com/atlassian/voyager/pkg/apis/orchestration/meta" | ||
"github.com/atlassian/voyager/pkg/orchestration/wiring/registry" | ||
"github.com/atlassian/voyager/pkg/orchestration/wiring/wiringplugin" | ||
"github.com/atlassian/voyager/pkg/orchestration/wiring/wiringutil/oap" | ||
"github.com/atlassian/voyager/pkg/util/crash" | ||
"k8s.io/klog" | ||
) | ||
|
@@ -23,18 +25,23 @@ const ( | |
) | ||
|
||
func Main() { | ||
CustomMain(emptyLegacyConfigFunc, registry.KnownWiringPlugins) | ||
CustomMain(registry.KnownWiringPlugins( | ||
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 looks better 👍 |
||
exampleDeveloperRole, | ||
exampleManagedPolicies, | ||
exampleVPC, | ||
exampleEnvironment, | ||
)) | ||
} | ||
|
||
func CustomMain(getLegacyConfigFunc func(voyager.Location) *legacy.Config, plugins map[voyager.ResourceType]wiringplugin.WiringPlugin) { | ||
func CustomMain(plugins map[voyager.ResourceType]wiringplugin.WiringPlugin) { | ||
rand.Seed(time.Now().UnixNano()) | ||
klog.InitFlags(nil) | ||
cmd.RunInterruptably(func(ctx context.Context) error { | ||
crash.InstallAPIMachineryLoggers() | ||
controllers := []ctrl.Constructor{ | ||
&ControllerConstructor{ | ||
GetLegacyConfigFunc: getLegacyConfigFunc, | ||
Plugins: plugins, | ||
Plugins: plugins, | ||
Tags: exampleTags, | ||
}, | ||
} | ||
|
||
|
@@ -48,6 +55,38 @@ func CustomMain(getLegacyConfigFunc func(voyager.Location) *legacy.Config, plugi | |
}) | ||
} | ||
|
||
func emptyLegacyConfigFunc(location voyager.Location) *legacy.Config { | ||
return &legacy.Config{} | ||
func exampleTags( | ||
_ voyager.ClusterLocation, | ||
_ wiringplugin.ClusterConfig, | ||
_ voyager.Location, | ||
_ voyager.ServiceName, | ||
_ orch_meta.ServiceProperties, | ||
) map[voyager.Tag]string { | ||
return make(map[voyager.Tag]string) | ||
} | ||
|
||
func exampleDeveloperRole(_ voyager.Location) []string { | ||
return strings.Split(os.Getenv("PLUGIN_DEVELOPER_ROLE"), ",") //example | ||
} | ||
func exampleManagedPolicies(_ voyager.Location) []string { | ||
return strings.Split(os.Getenv("PLUGIN_MANAGED_POLICIES"), ",") | ||
} | ||
func exampleVPC(location voyager.Location) *oap.VPCEnvironment { | ||
return &oap.VPCEnvironment{ | ||
VPCID: os.Getenv("PLUGIN_VPC_ID"), | ||
PrivateDNSZone: os.Getenv("PLUGIN_PRIVATE_DNS_ZONE"), | ||
PrivatePaasDNSZone: os.Getenv("PLUGIN_PRIVATE_PAAS_DNS_ZONE"), | ||
InstanceSecurityGroup: os.Getenv("PLUGIN_INSTANCE_SECURITY_GROUP"), | ||
JumpboxSecurityGroup: os.Getenv("PLUGIN_JUMP_BOX_SECURITY_GROUP"), | ||
SSLCertificateID: os.Getenv("PLUGIN_SSL_CERT_ID"), | ||
Label: location.Label, | ||
AppSubnets: strings.Split(os.Getenv("PLUGIN_APP_SUBNETS"), ","), | ||
Zones: strings.Split(os.Getenv("PLUGIN_ZONES"), ","), | ||
Region: location.Region, | ||
EMRSubnet: os.Getenv("EMR_SUBNET"), | ||
} | ||
} | ||
|
||
func exampleEnvironment(_ voyager.Location) string { | ||
return os.Getenv("PLUGIN_ENVIRONMENT") | ||
} |
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 ( | ||
|
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.