Skip to content
This repository has been archived by the owner on Aug 4, 2022. It is now read-only.

Update SF labels to use explicit methods and add missing labels #16

Merged
merged 15 commits into from
Mar 22, 2018

Conversation

lawrencegripper
Copy link
Contributor

Hi,

This is WIP at the moment but I wanted to check in before I go much further - in case this is the wrong direction.

  • I've started to add a few additional labels using explicit methods, as discussed in Review supported labels in the provider and add those missing #3. Adding PassTLSCert, FrameDeny and RequestHeaders
  • I've tried to bring existing SF labels in line with those in providers/labels so isExposed -> Enabled
  • To make sure they behave as expected I've created a new test
  • I've renamed existing label functions to ensure those that return a func are have func in the name and those that don't don't

Let me know if this all makes sense and I'll continue to add the remaining labels from the docker provider implementation in v1.5

@ldez ldez changed the base branch from mrg-current-1.0 to master December 15, 2017 14:16
@ldez ldez added this to the traefik-v1.6 milestone Dec 15, 2017
@ldez
Copy link
Contributor

ldez commented Dec 15, 2017

FYI:

  • master -> Træfik 1.6
  • v1.0 -> Træfik 1.5

I assume the tests are in WIP but I think we must change the way that we test:

  • updateConfig: must have tests only on the configuration update (add/remove/change)
  • buildConfiguration: must have tests on labels

We must remove tests on labels from updateConfig tests.

@lawrencegripper
Copy link
Contributor Author

lawrencegripper commented Dec 15, 2017

Thanks. Wasn't sure what to work off :)

Good Idea, I'll reformat the labels tests I added to use buildConfiguration.

Shall I tackle splitting the updateConfig test in this PR or handle it separately? I think it would be better split into three tests

  1. Update config - Is the config sent to the channel. Content is not relevant.
  2. Services present - This can use BuildConfiguration. It should check services exposed by the sfsdk are present in the config message
  3. Labels tests - Use the new test TestFrontendLabelConfig and create TestBackendLabelConfig to cover these cases

Sound like a good plan?

On an unrelated note is there a reason the MakeFile uses this syntax gometalinter --vendor --enable=misspell ./... not gometalinter --vendor --enable=misspell $(PKGS)

@ldez
Copy link
Contributor

ldez commented Dec 15, 2017

Sound like a very good plan! 😄

gometalinter support vendor system via --vendor since go1.5/1.6

Before go1.9, go test runs tests from vendor folder 😞 I use $(PKGS) in go test due that.
But this can be remove because Traefik support only go1.9+.

@lawrencegripper
Copy link
Contributor Author

Test refactoring is done (hopefully), if it looks good I'll add in additional use cases and start working on the additional labels too.

@lawrencegripper
Copy link
Contributor Author

@ldez Hey, gometalinter fails on gocyclo tests for the labels test as it's quite long one now.

I've looked at trying to break it up but, imo, it makes it harder to read and update (for example pulling out each validate func into a full func rather than inline). Happy to split it up if that would be your preference.

No rush on this as I'm on leave from today until the new year so unlikely to be doing a huge amount on it.

@ldez
Copy link
Contributor

ldez commented Dec 22, 2017

You can split in 2 test methods:

  • one for frontend labels
  • one for backend labels

WDYT?

@lawrencegripper
Copy link
Contributor Author

Good call but already have that. gocyclo still fails because there are lots of frontend labels to test, I'll maybe have a play at pulling out the testcase items into loosely grouped vars outside of the test method. Like security, headers etc.

I did stop for a bit and think that the tests were overkill but as it's easy to edit the tmpl file and not notice it causing a bug with a label I do think they are of value.

WDYT?

@ldez
Copy link
Contributor

ldez commented Dec 22, 2017

I will try to customize the gocylo configuration.

@ldez
Copy link
Contributor

ldez commented Jan 5, 2018

gocyclo doesn't have "real" configuration.

I think we can add // nocyclo on the frond of the test method, not really happy with this but it's the only way.

// nocyclo
func TestFrontendLabelConfig(t *testing.T){
// ...
}

// nocyclo
func TestBackendLabelConfig(t *testing.T){
// ...
}

@ldez
Copy link
Contributor

ldez commented Jan 5, 2018

Sorry mistake, it's // nolint: gocyclo

@lawrencegripper
Copy link
Contributor Author

lawrencegripper commented Jan 5, 2018

np, should have tested it locally - did the trick there are some failing tests which I'm expecting during the refactoring

@lawrencegripper
Copy link
Contributor Author

@ldez hopefully this is no-longer WIP and ready for review

Copy link

@jjcollinge jjcollinge left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lawrencegripper few quick notes

@@ -58,7 +61,7 @@ const tmpl = `
{{range $replica := $partition.Replicas}}
{{if isPrimary $replica}}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How to route to secondaries when listenOnSecondary enabled - can be added later.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oooh interesting, lets chat about this one maybe best as a separate PR as this is already pretty chunky

{{range $partition := $service.Partitions}}
{{if eq $partition.ServiceKind "Stateless"}}
{{if eq $partition.ServiceKind "Stateless"}}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be a function isStateless rather than a hard-coded string?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done now, brain dead simple func but added some tests too

servicefabric.go Outdated

return p.GetConfiguration(tmpl, sfFuncMap, templateObjects)
}

func getDefaultEndpoint(instance replicaInstance) string {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: order functions in servicefabric.go for readability:

  1. local functions i.e. getClusterServices
  2. template functions i.e. getDefaultEndpoint
  3. helper functions i.e. decodeEndpointData

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good spot, I've gone a step further and moved template funcs into config.go so only funcs related to enumerating services are left in this file. Think it makes things cleaner - what do you think?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah makes sense.

Copy link
Contributor

@ldez ldez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@ldez ldez force-pushed the addlabels branch 2 times, most recently from a924bdd to 9693d1b Compare March 21, 2018 20:16
@jjcollinge
Copy link

LGTM

@ldez ldez merged commit a0b2008 into master Mar 22, 2018
@ldez ldez deleted the addlabels branch March 22, 2018 09:39
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants