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

Refactor label parsing to set OF labels last #229

Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Update label constants to remove OF prefix
Signed-off-by: Lucas Roesler <[email protected]>
  • Loading branch information
LucasRoesler committed Oct 7, 2018
commit 5344c15d8959d84046e767f0fe8c49cc208df6d0
2 changes: 1 addition & 1 deletion handlers/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func MakeDeleteHandler(functionNamespace string, clientset *kubernetes.Clientset

func isFunction(deployment *v1beta1.Deployment) bool {
if deployment != nil {
if _, found := deployment.Labels[OFFunctionNameLabel]; found {
if _, found := deployment.Labels[FunctionNameLabel]; found {
return true
}
}
Expand Down
4 changes: 2 additions & 2 deletions handlers/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ func makeDeploymentSpec(request requests.CreateFunctionRequest, existingSecrets
Spec: v1beta1.DeploymentSpec{
Selector: &metav1.LabelSelector{
MatchLabels: map[string]string{
OFFunctionNameLabel: request.Service,
FunctionNameLabel: request.Service,
},
},
Replicas: initialReplicas,
Expand Down Expand Up @@ -266,7 +266,7 @@ func makeServiceSpec(request requests.CreateFunctionRequest) *corev1.Service {
Spec: corev1.ServiceSpec{
Type: corev1.ServiceTypeClusterIP,
Selector: map[string]string{
OFFunctionNameLabel: request.Service,
FunctionNameLabel: request.Service,
},
Ports: []corev1.ServicePort{
{
Expand Down
12 changes: 6 additions & 6 deletions handlers/labels.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ const (
// also used as the default return value for getMinReplicaCount
initialReplicasCount = 1

// OFFunctionNameLabel is the label key used by OpenFaaS to store the function name
// FunctionNameLabel is the label key used by OpenFaaS to store the function name
// on the resources managed by OpenFaaS for that function. This key is also used to
// denote that a resource is a "Function"
OFFunctionNameLabel = "faas_function"
// OFFunctionMinReplicaCount is a label that user's can set and will be passed to Kubernetes
FunctionNameLabel = "faas_function"
// FunctionMinReplicaCount is a label that user's can set and will be passed to Kubernetes
// as the Deployment replicas value.
OFFunctionMinReplicaCount = "com.openfaas.scale.min"
FunctionMinReplicaCount = "com.openfaas.scale.min"
)

// parseLabels will copy the user request labels and ensure that any required internal labels
Expand All @@ -29,7 +29,7 @@ func parseLabels(functionName string, requestLables *map[string]string) map[stri
}
}

labels[OFFunctionNameLabel] = functionName
labels[FunctionNameLabel] = functionName

return labels
}
Expand All @@ -42,7 +42,7 @@ func getMinReplicaCount(labels *map[string]string) *int32 {
}

l := *labels
if value, exists := l[OFFunctionMinReplicaCount]; exists {
if value, exists := l[FunctionMinReplicaCount]; exists {
minReplicas, err := strconv.Atoi(value)
if err == nil && minReplicas > 0 {
return int32p(int32(minReplicas))
Expand Down
12 changes: 6 additions & 6 deletions handlers/lables_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func Test_getMinReplicaCount(t *testing.T) {
},
{
name: "empty map returns default",
labels: &map[string]string{OFFunctionMinReplicaCount: "2"},
labels: &map[string]string{FunctionMinReplicaCount: "2"},
output: 2,
},
}
Expand Down Expand Up @@ -51,19 +51,19 @@ func Test_parseLabels(t *testing.T) {
name: "nil map returns just the function name",
labels: nil,
functionName: "testFunc",
output: map[string]string{OFFunctionNameLabel: "testFunc"},
output: map[string]string{FunctionNameLabel: "testFunc"},
},
{
name: "empty map returns just the function name",
labels: &map[string]string{},
functionName: "testFunc",
output: map[string]string{OFFunctionNameLabel: "testFunc"},
output: map[string]string{FunctionNameLabel: "testFunc"},
},
{
name: "non-empty map does not overwrite the function name label",
labels: &map[string]string{OFFunctionNameLabel: "anotherValue", "customLabel": "test"},
labels: &map[string]string{FunctionNameLabel: "anotherValue", "customLabel": "test"},
functionName: "testFunc",
output: map[string]string{OFFunctionNameLabel: "testFunc", "customLabel": "test"},
output: map[string]string{FunctionNameLabel: "testFunc", "customLabel": "test"},
},
}

Expand All @@ -74,7 +74,7 @@ func Test_parseLabels(t *testing.T) {
t.Errorf("parseLabels should not return nil map")
}

outputFuncName := output[OFFunctionNameLabel]
outputFuncName := output[FunctionNameLabel]
if outputFuncName != s.functionName {
t.Errorf("parseLabels should always set the function name: expected %s, got %s", s.functionName, outputFuncName)
}
Expand Down
2 changes: 1 addition & 1 deletion handlers/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func getServiceList(functionNamespace string, clientset *kubernetes.Clientset) (
functions := []requests.Function{}

listOpts := metav1.ListOptions{
LabelSelector: OFFunctionNameLabel,
LabelSelector: FunctionNameLabel,
}

res, err := clientset.ExtensionsV1beta1().Deployments(functionNamespace).List(listOpts)
Expand Down