-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Generic sks helpers for pa #3705
Merged
knative-prow-robot
merged 4 commits into
knative:master
from
vagababov:generic-sks-helpers-for-pa
Apr 10, 2019
Merged
Changes from 3 commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/* | ||
Copyright 2019 The Knative Authors | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
// Package resources contains methods for manipulating K8s resources | ||
// shared between different PA implementations. | ||
package resources |
19 changes: 19 additions & 0 deletions
19
pkg/reconciler/v1alpha1/autoscaling/resources/names/doc.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/* | ||
Copyright 2019 The Knative Authors | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
// Package names contains methods for manipulating K8s resources' names | ||
// shared between different PA implementations. | ||
package names |
23 changes: 23 additions & 0 deletions
23
pkg/reconciler/v1alpha1/autoscaling/resources/names/names.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* | ||
Copyright 2019 The Knative Authors | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
// Package names contains name generating functions for the pod autoscalers. | ||
package names | ||
|
||
// SKSreturns the name of the SKS resource that backs this PA. | ||
func SKS(paName string) string { | ||
return paName | ||
} |
25 changes: 25 additions & 0 deletions
25
pkg/reconciler/v1alpha1/autoscaling/resources/names/names_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* | ||
Copyright 2019 The Knative Authors | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package names | ||
|
||
import "testing" | ||
|
||
func TestSKS(t *testing.T) { | ||
if got, want := SKS("ristretto"), "ristretto"; got != want { | ||
t.Errorf("SKSName = %q, want: %q", got, want) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
Copyright 2019 The Knative Authors | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package resources | ||
|
||
import ( | ||
"github.com/knative/pkg/kmeta" | ||
"github.com/knative/serving/pkg/apis/autoscaling" | ||
pav1alpha1 "github.com/knative/serving/pkg/apis/autoscaling/v1alpha1" | ||
nv1a1 "github.com/knative/serving/pkg/apis/networking/v1alpha1" | ||
"github.com/knative/serving/pkg/reconciler/v1alpha1/autoscaling/resources/names" | ||
"github.com/knative/serving/pkg/resources" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
) | ||
|
||
// MakeSKS makes an SKS resource from the PA, selector and operation mode. | ||
func MakeSKS(pa *pav1alpha1.PodAutoscaler, selector map[string]string, mode nv1a1.ServerlessServiceOperationMode) *nv1a1.ServerlessService { | ||
return &nv1a1.ServerlessService{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: names.SKS(pa.Name), | ||
Namespace: pa.Namespace, | ||
Labels: resources.CopyMap(pa.GetLabels()), | ||
Annotations: resources.FilterMap(pa.GetAnnotations(), func(s string) bool { | ||
return s == autoscaling.MetricAnnotationKey | ||
|
||
}), | ||
OwnerReferences: []metav1.OwnerReference{*kmeta.NewControllerRef(pa)}, | ||
}, | ||
Spec: nv1a1.ServerlessServiceSpec{ | ||
Selector: selector, | ||
Mode: mode, | ||
ProtocolType: pa.Spec.ProtocolType, | ||
}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
/* | ||
Copyright 2019 The Knative Authors | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package resources | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/google/go-cmp/cmp" | ||
pav1a1 "github.com/knative/serving/pkg/apis/autoscaling/v1alpha1" | ||
"github.com/knative/serving/pkg/apis/networking" | ||
nv1a1 "github.com/knative/serving/pkg/apis/networking/v1alpha1" | ||
"github.com/knative/serving/pkg/apis/serving" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
) | ||
|
||
var boolTrue = true | ||
|
||
// MakeSKS makes an SKS resource from the PA, selector and operation mode. | ||
func TestMakeSKS(t *testing.T) { | ||
pa := &pav1a1.PodAutoscaler{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Namespace: "here", | ||
Name: "with-you", | ||
UID: "2006", | ||
// Those labels are propagated from the Revision->KPA. | ||
Labels: map[string]string{ | ||
serving.RevisionLabelKey: "with-you", | ||
serving.RevisionUID: "2009", | ||
}, | ||
Annotations: map[string]string{ | ||
"a": "b", | ||
}, | ||
}, | ||
Spec: pav1a1.PodAutoscalerSpec{ | ||
ProtocolType: networking.ProtocolHTTP1, | ||
}, | ||
} | ||
|
||
selector := map[string]string{"cant": "stop"} | ||
const mode = nv1a1.SKSOperationModeServe | ||
|
||
want := &nv1a1.ServerlessService{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Namespace: "here", | ||
Name: "with-you", | ||
// Those labels are propagated from the Revision->KPA. | ||
Labels: map[string]string{ | ||
serving.RevisionLabelKey: "with-you", | ||
serving.RevisionUID: "2009", | ||
}, | ||
Annotations: map[string]string{ | ||
"a": "b", | ||
}, | ||
OwnerReferences: []metav1.OwnerReference{{ | ||
APIVersion: pav1a1.SchemeGroupVersion.String(), | ||
Kind: "PodAutoscaler", | ||
Name: "with-you", | ||
UID: "2006", | ||
Controller: &boolTrue, | ||
BlockOwnerDeletion: &boolTrue, | ||
}}, | ||
}, | ||
Spec: nv1a1.ServerlessServiceSpec{ | ||
ProtocolType: networking.ProtocolHTTP1, | ||
Mode: nv1a1.SKSOperationModeServe, | ||
Selector: selector, | ||
}, | ||
} | ||
if got, want := MakeSKS(pa, selector, mode), want; !cmp.Equal(got, want) { | ||
t.Errorf("MakeSKS = %#v, want: %#v, diff: %s", got, want, cmp.Diff(got, want)) | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
space
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.
ouais, I notice :)