Skip to content
This repository has been archived by the owner on Oct 11, 2019. It is now read-only.

Commit

Permalink
Merge branch 'master' into remove_legacy
Browse files Browse the repository at this point in the history
  • Loading branch information
amckague committed Feb 14, 2019
2 parents c613565 + 467d3d6 commit e51288a
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 34 deletions.
26 changes: 16 additions & 10 deletions pkg/orchestration/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,9 @@ func (c *Controller) Process(ctx *ctrl.ProcessContext) (retriable bool, err erro
// process processes the given State object performing autowiring for it.
// It tries to return a Bundle even if there was an error.
func (c *Controller) process(logger *zap.Logger, state *orch_v1.State) (*smith_v1.Bundle, bool /* external */, bool /* conflict */, bool /* retriable */, error) {
entanglerContext, err := c.constructEntanglerContext(state)
entanglerContext, external, retriable, err := c.constructEntanglerContext(state)
if err != nil {
return nil, false, false, false, err
return nil, external, false, retriable, err
}

bundle, external, retriable, err := c.entangle(state, entanglerContext)
Expand All @@ -135,41 +135,47 @@ func (c *Controller) process(logger *zap.Logger, state *orch_v1.State) (*smith_v

}

func (c *Controller) constructEntanglerContext(state *orch_v1.State) (*wiring.EntangleContext, error) {
func (c *Controller) constructEntanglerContext(state *orch_v1.State) (*wiring.EntangleContext, bool /* externalErr */, bool /* retriable */, error) {
// Grab the namespace
namespaceObj, exists, err := c.NamespaceInformer.GetIndexer().GetByKey(state.Namespace)
if err != nil {
return nil, errors.WithStack(err)
// Should not happen
return nil, false, false, errors.WithStack(err)
}
if !exists {
return nil, errors.Errorf("missing Namespace %q in informer", state.Namespace)
// Namespace was deleted while we are processing. Should not happen.
return nil, false, false, errors.Errorf("missing Namespace %q in informer", state.Namespace)
}
namespace := namespaceObj.(*core_v1.Namespace)

key := ByConfigMapNameIndexKey(state.Namespace, state.Spec.ConfigMapName)
configMapInterface, exists, err := c.ConfigMapInformer.GetIndexer().GetByKey(key)
if err != nil {
return nil, errors.WithStack(err)
// Should not happen
return nil, false, false, errors.WithStack(err)
}
if !exists {
return nil, errors.Errorf("missing ConfigMap %q (key: %q) in informer", state.Spec.ConfigMapName, key)
// This indicates an external error because this means the metadata configmap
// is missing (the user or layer above has not provided the configmap).
return nil, true, false, errors.Errorf("missing ConfigMap %q (key: %q) in informer", state.Spec.ConfigMapName, key)
}
serviceProperties, err := parseConfigMap(configMapInterface.(*core_v1.ConfigMap))
if err != nil {
return nil, errors.WithStack(err)
return nil, true, false, errors.WithStack(err)
}

serviceName, err := layers.ServiceNameFromNamespaceLabels(namespace.Labels)
if err != nil {
return nil, err
// User error too, we expect the namespace to contain the service name label.
return nil, true, false, err
}

// Entangle the State
return &wiring.EntangleContext{
ServiceName: serviceName,
Label: layers.ServiceLabelFromNamespaceLabels(namespace.Labels),
ServiceProperties: *serviceProperties,
}, nil
}, false, false, nil
}

func (c *Controller) entangle(state *orch_v1.State, entangleContext *wiring.EntangleContext) (*smith_v1.Bundle, bool /* external */, bool /* retriable */, error) {
Expand Down
3 changes: 2 additions & 1 deletion pkg/orchestration/wiring/aws/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@ go_library(
"//pkg/orchestration/wiring/wiringutil:go_default_library",
"//pkg/orchestration/wiring/wiringutil/knownshapes:go_default_library",
"//pkg/orchestration/wiring/wiringutil/oap:go_default_library",
"//pkg/orchestration/wiring/wiringutil/osb:go_default_library",
"//pkg/orchestration/wiring/wiringutil/svccatentangler:go_default_library",
"//pkg/servicecatalog:go_default_library",
"//vendor/github.com/atlassian/smith/pkg/apis/smith/v1:go_default_library",
"//vendor/github.com/pkg/errors:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/runtime:go_default_library",
],
)
95 changes: 74 additions & 21 deletions pkg/orchestration/wiring/aws/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,26 @@ package aws
import (
"encoding/json"

smith_v1 "github.com/atlassian/smith/pkg/apis/smith/v1"
"github.com/atlassian/voyager"
orch_v1 "github.com/atlassian/voyager/pkg/apis/orchestration/v1"
"github.com/atlassian/voyager/pkg/orchestration/wiring/wiringplugin"
"github.com/atlassian/voyager/pkg/orchestration/wiring/wiringutil"
"github.com/atlassian/voyager/pkg/orchestration/wiring/wiringutil/oap"
"github.com/atlassian/voyager/pkg/orchestration/wiring/wiringutil/osb"
"github.com/atlassian/voyager/pkg/orchestration/wiring/wiringutil/svccatentangler"
"github.com/atlassian/voyager/pkg/servicecatalog"
"github.com/pkg/errors"
meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
)

type ServiceEnvironmentGenerator func(env *oap.ServiceEnvironment) *oap.ServiceEnvironment

type WiringPlugin struct {
svccatentangler.SvcCatEntangler
clusterServiceClassExternalID servicecatalog.ClassExternalID
clusterServicePlanExternalID servicecatalog.PlanExternalID
resourceType voyager.ResourceType
shapes svccatentangler.ShapesFunc // TODO move from svccatentangler package to this package

OAPResourceTypeName oap.ResourceType
generateServiceEnvironment ServiceEnvironmentGenerator
Expand All @@ -41,22 +47,73 @@ func Resource(resourceType voyager.ResourceType,
vpc func(voyager.Location) *oap.VPCEnvironment,
) *WiringPlugin {
wiringPlugin := &WiringPlugin{
SvcCatEntangler: svccatentangler.SvcCatEntangler{
ClusterServiceClassExternalID: clusterServiceClassExternalID,
ClusterServicePlanExternalID: clusterServicePlanExternalID,
ResourceType: resourceType,
Shapes: shapes,
},
OAPResourceTypeName: oapResourceTypeName,
generateServiceEnvironment: generateServiceEnvironment,
VPC: vpc,
clusterServiceClassExternalID: clusterServiceClassExternalID,
clusterServicePlanExternalID: clusterServicePlanExternalID,
resourceType: resourceType,
shapes: shapes,
OAPResourceTypeName: oapResourceTypeName,
generateServiceEnvironment: generateServiceEnvironment,
VPC: vpc,
}
wiringPlugin.SvcCatEntangler.InstanceSpec = wiringPlugin.instanceSpec
wiringPlugin.SvcCatEntangler.ObjectMeta = wiringPlugin.objectMeta
return wiringPlugin
}

func (awp *WiringPlugin) instanceSpec(resource *orch_v1.StateResource, context *wiringplugin.WiringContext) ([]byte, bool /* externalError */, bool /* retriableError */, error) {
func (p *WiringPlugin) WireUp(resource *orch_v1.StateResource, context *wiringplugin.WiringContext) wiringplugin.WiringResult {
if resource.Type != p.resourceType {
return &wiringplugin.WiringResultFailure{
Error: errors.Errorf("invalid resource type: %q", resource.Type),
}
}

serviceInstance, err := osb.ConstructServiceInstance(resource, p.clusterServiceClassExternalID, p.clusterServicePlanExternalID)
if err != nil {
return &wiringplugin.WiringResultFailure{
Error: err,
}
}

instanceParameters, external, retriable, err := p.instanceParameters(resource, context)
if err != nil {
return &wiringplugin.WiringResultFailure{
Error: err,
IsExternalError: external,
IsRetriableError: retriable,
}
}
if instanceParameters != nil {
serviceInstance.Spec.Parameters = &runtime.RawExtension{
Raw: instanceParameters,
}
}

instanceResourceName := wiringutil.ServiceInstanceResourceName(resource.Name)

smithResource := smith_v1.Resource{
Name: instanceResourceName,
References: nil, // no references
Spec: smith_v1.ResourceSpec{
Object: serviceInstance,
},
}

shapes, external, retriable, err := p.shapes(resource, &smithResource, context)
if err != nil {
return &wiringplugin.WiringResultFailure{
Error: err,
IsExternalError: external,
IsRetriableError: retriable,
}
}

return &wiringplugin.WiringResultSuccess{
Contract: wiringplugin.ResourceContract{
Shapes: shapes,
},
Resources: []smith_v1.Resource{smithResource},
}
}

func (p *WiringPlugin) instanceParameters(resource *orch_v1.StateResource, context *wiringplugin.WiringContext) ([]byte, bool /* externalError */, bool /* retriableError */, error) {
rawAttributes, external, retriable, err := oap.BuildAttributes(resource.Spec, resource.Defaults)
if err != nil {
return nil, external, retriable, err
Expand Down Expand Up @@ -90,13 +147,9 @@ func (awp *WiringPlugin) instanceSpec(resource *orch_v1.StateResource, context *
}

serviceName := serviceName(userServiceName, context)
vpc := awp.VPC(context.StateContext.Location)
environment := awp.generateServiceEnvironment(oap.MakeServiceEnvironmentFromContext(context, vpc))
return instanceSpec(serviceName, resourceName, awp.OAPResourceTypeName, *environment, attributes, alarms)
}

func (awp *WiringPlugin) objectMeta(resource *orch_v1.StateResource, context *wiringplugin.WiringContext) (meta_v1.ObjectMeta, bool /* externalErr */, bool /* retriableErr */, error) {
return meta_v1.ObjectMeta{}, false, false, nil
vpc := p.VPC(context.StateContext.Location)
environment := p.generateServiceEnvironment(oap.MakeServiceEnvironmentFromContext(context, vpc))
return instanceSpec(serviceName, resourceName, p.OAPResourceTypeName, *environment, attributes, alarms)
}

func serviceName(userServiceName voyager.ServiceName, context *wiringplugin.WiringContext) voyager.ServiceName {
Expand Down
2 changes: 2 additions & 0 deletions pkg/orchestration/wiring/wiringutil/svccatentangler/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ type ShapesFunc func(resource *orch_v1.StateResource, smithResource *smith_v1.Re
// list of smith references through References().
//
// This is for WiringPlugins that will create a ServiceInstance.

// DEPRECATED: Use helper functions from 'osb' package instead.
type SvcCatEntangler struct {

// This identifies what resource types can be processed.
Expand Down
5 changes: 5 additions & 0 deletions pkg/servicecentral/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,11 @@ func (c *Store) ListModifiedServices(ctx context.Context, user auth.OptionalUser
// Feature request: https://sdog.jira-dev.com/browse/MICROSCOPE-280
continue
}
if serviceData.ServiceName == "" {
// Central can contain broken data
// https://sdog.jira-dev.com/projects/MICROSHELP/queues/issue/MICROSHELP-5863
continue
}
svc, err := serviceDataToService(&serviceData)
if err != nil {
return nil, err
Expand Down
4 changes: 2 additions & 2 deletions shell.nix
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,14 @@ pkgs.mkShell {
# manually edit workspace (select doesn't work with bazel macros)
# possibly could be done with some sort of wrapper macro instead
git update-index --assume-unchanged WORKSPACE
sed -i -e 's/go_register_toolchains(nogo = "@//:nogo")/go_register_toolchains(nogo = "@//:nogo", go_version = "host")/g' WORKSPACE
sed -i -e 's$go_register_toolchains(nogo = "@//:nogo")$go_register_toolchains(nogo = "@//:nogo", go_version = "host")$g' WORKSPACE
}
function teardown() {
sed -i '/build --python_path=*/d' user.bazelrc
sed -i '/test --python_path=*/d' user.bazelrc
sed -i -e 's/go_register_toolchains(nogo = "@//:nogo", go_version = "host")/go_register_toolchains(nogo = "@//:nogo")/g' WORKSPACE
sed -i -e 's$go_register_toolchains(nogo = "@//:nogo", go_version = "host")$go_register_toolchains(nogo = "@//:nogo")$g' WORKSPACE
git update-index --no-assume-unchanged WORKSPACE
if [ ! -s user.bazelrc ] ; then
Expand Down

0 comments on commit e51288a

Please sign in to comment.