Skip to content
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

[WIP] Function label constraints #178

Closed

Conversation

kinghuang
Copy link
Contributor

A WIP implementation of Option E from #175 to allow service label filters to be configured on the gateway.

Description

Add an environment config named faas_function_filters to the gateway. It is a comma-separated list of label filters used filter Docker services when reading the list of functions for the gateway. It is parsed into a string array and stored in a new field named FunctionFilters in GatewayConfig.

Motivation and Context

When multiple gateways are deployed on a swarm, there is no way to configure gateways to pick up only certain functions. As a result, functions from different stacks or different deployments of the same stack “leak” into each other. This is a WIP implementation of one of the possible options for configuring the gateway to read only certain function services.

This implementation is for Option E in proposal issue #175, and aims to solve issue #55.

  • I have raised an issue to propose this change (required)

How Has This Been Tested?

The docker-compose.yml file in this branch has been temporarily changed to filter for hello=world, and the hubstats function has been labeled to match. The gateway correctly picks up just that one function. If the faas_function_filters environment variable is removed, all the functions in the stack are read as before.

This currently breaks adding a new function in the UI, because the created service lacks the labels specified in faas_function_filters.

Also, this filtering is based on labels on services, not containers. It might be worth considering moving the function label to the service level for uniformity. However, that would be a breaking change.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

This becomes a breaking change if the function label is moved to the service level.

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I've read the CONTRIBUTION guide
  • I have signed-off my commits with git commit -s
  • I have added tests to cover my changes.
  • All new and existing tests passed.

The faas_function_filters environment variable can be used to specify
service filters for the gateway. Only function services matching the
filter conditions will be picked up by the gateway.

Multiple filters can be specified as comma-separated values.

Signed-off-by: King Chung Huang <kinghuang@mac.com>
Add a serviceLabelFilters argument to MakeFunctionReader. Any specified
label filters will be added to the serviceFilter when getting the list
of Docker services to check for functions.

Signed-off-by: King Chung Huang <kinghuang@mac.com>
Pass the FunctionFilters config as the list of service label filters to
MakeFunctionReader. Any specified filters will be used when getting the
list of services in the Docker swarm for consideration as functions.

Signed-off-by: King Chung Huang <kinghuang@mac.com>
Temporarily set faas_function_filters to hello=world on the gateway and
add the corresponding label to hubstats to demonstrate the use of the
label filter.

Signed-off-by: King Chung Huang <kinghuang@mac.com>
@alexellis
Copy link
Member

Related: openfaas/faas-netes#20

@alexellis
Copy link
Member

@kinghuang - where are you with this? Btw we have merge conflicts and commits need squashing.

@@ -5,11 +5,12 @@ services:
- "/var/run/docker.sock:/var/run/docker.sock"
ports:
- 8080:8080
image: functions/gateway:0.6.3
image: functions/gateway:latest-dev
Copy link
Member

Choose a reason for hiding this comment

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

This line shouldn't have changed.

@alexellis
Copy link
Member

@kinghuang please see changes in latest release of the gateway and CLI to support labels.

@alexellis
Copy link
Member

Closing as inactive. I believe we have this supported in the code now via other PRs.

@alexellis alexellis closed this Nov 30, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants