mirror of https://github.com/knative/pkg.git
Adding Batch v1 Job to injection client. (#459)
* adding Batch v1 Job to injection client. * damn lock file.
This commit is contained in:
parent
c2f344436b
commit
68737b1b4e
|
|
@ -1171,6 +1171,7 @@
|
|||
"k8s.io/client-go/informers/apps/v1",
|
||||
"k8s.io/client-go/informers/autoscaling/v1",
|
||||
"k8s.io/client-go/informers/autoscaling/v2beta1",
|
||||
"k8s.io/client-go/informers/batch/v1",
|
||||
"k8s.io/client-go/informers/core/v1",
|
||||
"k8s.io/client-go/informers/rbac/v1",
|
||||
"k8s.io/client-go/kubernetes",
|
||||
|
|
|
|||
|
|
@ -0,0 +1,38 @@
|
|||
/*
|
||||
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 fake
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/knative/pkg/controller"
|
||||
"github.com/knative/pkg/injection"
|
||||
"github.com/knative/pkg/injection/informers/kubeinformers/batchv1/job"
|
||||
"github.com/knative/pkg/injection/informers/kubeinformers/factory/fake"
|
||||
)
|
||||
|
||||
var Get = job.Get
|
||||
|
||||
func init() {
|
||||
injection.Fake.RegisterInformer(withInformer)
|
||||
}
|
||||
|
||||
func withInformer(ctx context.Context) (context.Context, controller.Informer) {
|
||||
f := fake.Get(ctx)
|
||||
inf := f.Batch().V1().Jobs()
|
||||
return context.WithValue(ctx, job.Key{}, inf), inf.Informer()
|
||||
}
|
||||
|
|
@ -0,0 +1,66 @@
|
|||
/*
|
||||
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 fake
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"k8s.io/client-go/rest"
|
||||
|
||||
"github.com/knative/pkg/controller"
|
||||
"github.com/knative/pkg/injection"
|
||||
)
|
||||
|
||||
func TestGetPanic(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
|
||||
defer func() {
|
||||
if r := recover(); r == nil {
|
||||
t.Error("Get() should have panicked")
|
||||
}
|
||||
}()
|
||||
|
||||
// Get before registration
|
||||
if empty := Get(ctx); empty != nil {
|
||||
t.Errorf("Unexpected informer: %v", empty)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRegistration(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
|
||||
// Check how many informers have registered.
|
||||
inffs := injection.Fake.GetInformers()
|
||||
if want, got := 1, len(inffs); want != got {
|
||||
t.Errorf("GetInformers() = %d, wanted %d", want, got)
|
||||
}
|
||||
|
||||
// Setup the informers.
|
||||
var infs []controller.Informer
|
||||
ctx, infs = injection.Fake.SetupInformers(ctx, &rest.Config{})
|
||||
|
||||
// We should see that a single informer was set up.
|
||||
if want, got := 1, len(infs); want != got {
|
||||
t.Errorf("SetupInformers() = %d, wanted %d", want, got)
|
||||
}
|
||||
|
||||
// Get our informer from the context.
|
||||
if inf := Get(ctx); inf == nil {
|
||||
t.Error("Get() = nil, wanted non-nil")
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,52 @@
|
|||
/*
|
||||
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 job
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
batchv1 "k8s.io/client-go/informers/batch/v1"
|
||||
|
||||
"github.com/knative/pkg/controller"
|
||||
"github.com/knative/pkg/injection"
|
||||
"github.com/knative/pkg/injection/informers/kubeinformers/factory"
|
||||
"github.com/knative/pkg/logging"
|
||||
)
|
||||
|
||||
func init() {
|
||||
injection.Default.RegisterInformer(withInformer)
|
||||
}
|
||||
|
||||
// Key is used as the key for associating information
|
||||
// with a context.Context.
|
||||
type Key struct{}
|
||||
|
||||
func withInformer(ctx context.Context) (context.Context, controller.Informer) {
|
||||
f := factory.Get(ctx)
|
||||
inf := f.Batch().V1().Jobs()
|
||||
return context.WithValue(ctx, Key{}, inf), inf.Informer()
|
||||
}
|
||||
|
||||
// Get extracts the Kubernetes Job informer from the context.
|
||||
func Get(ctx context.Context) batchv1.JobInformer {
|
||||
untyped := ctx.Value(Key{})
|
||||
if untyped == nil {
|
||||
logging.FromContext(ctx).Panicf(
|
||||
"Unable to fetch %T from context.", (batchv1.JobInformer)(nil))
|
||||
}
|
||||
return untyped.(batchv1.JobInformer)
|
||||
}
|
||||
|
|
@ -0,0 +1,66 @@
|
|||
/*
|
||||
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 job
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"k8s.io/client-go/rest"
|
||||
|
||||
"github.com/knative/pkg/controller"
|
||||
"github.com/knative/pkg/injection"
|
||||
)
|
||||
|
||||
func TestGetPanic(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
|
||||
defer func() {
|
||||
if r := recover(); r == nil {
|
||||
t.Error("Get() should have panicked")
|
||||
}
|
||||
}()
|
||||
|
||||
// Get before registration
|
||||
if empty := Get(ctx); empty != nil {
|
||||
t.Errorf("Unexpected informer: %v", empty)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRegistration(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
|
||||
// Check how many informers have registered.
|
||||
inffs := injection.Default.GetInformers()
|
||||
if want, got := 1, len(inffs); want != got {
|
||||
t.Errorf("GetInformers() = %d, wanted %d", want, got)
|
||||
}
|
||||
|
||||
// Setup the informers.
|
||||
var infs []controller.Informer
|
||||
ctx, infs = injection.Default.SetupInformers(ctx, &rest.Config{})
|
||||
|
||||
// We should see that a single informer was set up.
|
||||
if want, got := 1, len(infs); want != got {
|
||||
t.Errorf("SetupInformers() = %d, wanted %d", want, got)
|
||||
}
|
||||
|
||||
// Get our informer from the context.
|
||||
if inf := Get(ctx); inf == nil {
|
||||
t.Error("Get() = nil, wanted non-nil")
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue