Skip to content
This repository has been archived by the owner on Sep 5, 2019. It is now read-only.

Vendor knative/caching and start instantiating them for sidecars. #348

Merged
merged 1 commit into from
Sep 14, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
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
30 changes: 28 additions & 2 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ required = [
"k8s.io/code-generator/cmd/client-gen",
"k8s.io/code-generator/cmd/lister-gen",
"k8s.io/code-generator/cmd/informer-gen",
"github.com/knative/caching/pkg/apis/caching",
"github.com/knative/test-infra",
]

Expand Down Expand Up @@ -63,6 +64,11 @@ required = [
unused-packages = false
non-go = false

[[prune.project]]
name = "github.com/knative/caching"
unused-packages = false
non-go = false

[[prune.project]]
name = "github.com/knative/test-infra"
unused-packages = false
Expand Down
21 changes: 16 additions & 5 deletions cmd/controller/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ import (

buildclientset "github.com/knative/build/pkg/client/clientset/versioned"
informers "github.com/knative/build/pkg/client/informers/externalversions"
cachingclientset "github.com/knative/caching/pkg/client/clientset/versioned"
cachinginformers "github.com/knative/caching/pkg/client/informers/externalversions"
"github.com/knative/pkg/configmap"
"github.com/knative/pkg/logging"
"github.com/knative/pkg/logging/logkey"
Expand Down Expand Up @@ -76,25 +78,32 @@ func main() {

cfg, err := clientcmd.BuildConfigFromFlags(*masterURL, *kubeconfig)
if err != nil {
logger.Fatalf("Error building kubeconfig: %s", err.Error())
logger.Fatalf("Error building kubeconfig: %v", err)
}

kubeClient, err := kubernetes.NewForConfig(cfg)
if err != nil {
logger.Fatalf("Error building kubernetes clientset: %s", err.Error())
logger.Fatalf("Error building kubernetes clientset: %v", err)
}

buildClient, err := buildclientset.NewForConfig(cfg)
if err != nil {
logger.Fatalf("Error building Build clientset: %s", err.Error())
logger.Fatalf("Error building Build clientset: %v", err)
}

cachingClient, err := cachingclientset.NewForConfig(cfg)
if err != nil {
logger.Fatalf("Error building Caching clientset: %v", err)
}

kubeInformerFactory := kubeinformers.NewSharedInformerFactory(kubeClient, time.Second*30)
buildInformerFactory := informers.NewSharedInformerFactory(buildClient, time.Second*30)
cachingInformerFactory := cachinginformers.NewSharedInformerFactory(cachingClient, time.Second*30)

buildInformer := buildInformerFactory.Build().V1alpha1().Builds()
buildTemplateInformer := buildInformerFactory.Build().V1alpha1().BuildTemplates()
clusterBuildTemplateInformer := buildInformerFactory.Build().V1alpha1().ClusterBuildTemplates()
imageInformer := cachingInformerFactory.Caching().V1alpha1().Images()

bldr := onclusterbuilder.NewBuilder(kubeClient, kubeInformerFactory, logger)

Expand All @@ -106,9 +115,9 @@ func main() {

build.NewController(logger, kubeClient, buildClient, buildInformer),
clusterbuildtemplate.NewController(logger, kubeClient, buildClient,
clusterBuildTemplateInformer),
cachingClient, clusterBuildTemplateInformer, imageInformer),
buildtemplate.NewController(logger, kubeClient, buildClient,
buildTemplateInformer),
cachingClient, buildTemplateInformer, imageInformer),
}

go kubeInformerFactory.Start(stopCh)
Expand All @@ -118,6 +127,8 @@ func main() {
buildInformer.Informer().HasSynced,
buildTemplateInformer.Informer().HasSynced,
clusterBuildTemplateInformer.Informer().HasSynced,
// TODO(mattmoor): Start waiting for sync after something sets up an event otherwise it hangs here.
// imageInformer.Informer().HasSynced,
} {
if ok := cache.WaitForCacheSync(stopCh, synced); !ok {
logger.Fatalf("failed to wait for cache at index %v to sync", i)
Expand Down
3 changes: 3 additions & 0 deletions config/200-clusterrole.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,6 @@ rules:
- apiGroups: ["build.knative.dev"]
resources: ["builds", "buildtemplates", "clusterbuildtemplates"]
verbs: ["get", "list", "create", "update", "delete", "patch", "watch"]
- apiGroups: ["caching.internal.knative.dev"]
resources: ["images"]
verbs: ["get", "list", "create", "update", "delete", "patch", "watch"]
1 change: 1 addition & 0 deletions config/300-imagecache.yaml
41 changes: 41 additions & 0 deletions config/999-cache.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Copyright 2018 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
#
# https://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.

apiVersion: caching.internal.knative.dev/v1alpha1
kind: Image
metadata:
name: creds-init
namespace: knative-build
spec:
# This is the Go import path for the binary that is containerized
# and substituted here.
image: github.com/knative/build/cmd/creds-init
---
apiVersion: caching.internal.knative.dev/v1alpha1
kind: Image
metadata:
name: git-init
imjasonh marked this conversation as resolved.
Show resolved Hide resolved
namespace: knative-build
spec:
# This is the Go import path for the binary that is containerized
# and substituted here.
image: github.com/knative/build/cmd/git-init
---
apiVersion: caching.internal.knative.dev/v1alpha1
kind: Image
metadata:
name: gcs-fetcher
namespace: knative-build
spec:
image: gcr.io/cloud-builders/gcs-fetcher
10 changes: 10 additions & 0 deletions pkg/reconciler/buildtemplate/buildtemplate.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ import (
buildscheme "github.com/knative/build/pkg/client/clientset/versioned/scheme"
informers "github.com/knative/build/pkg/client/informers/externalversions/build/v1alpha1"
listers "github.com/knative/build/pkg/client/listers/build/v1alpha1"
cachingclientset "github.com/knative/caching/pkg/client/clientset/versioned"
cachinginformers "github.com/knative/caching/pkg/client/informers/externalversions/caching/v1alpha1"
cachinglisters "github.com/knative/caching/pkg/client/listers/caching/v1alpha1"
)

const controllerAgentName = "buildtemplate-controller"
Expand All @@ -43,8 +46,11 @@ type Reconciler struct {
kubeclientset kubernetes.Interface
// buildclientset is a clientset for our own API group
buildclientset clientset.Interface
// cachingclientset is a clientset for creating caching resources.
cachingclientset cachingclientset.Interface

buildTemplatesLister listers.BuildTemplateLister
imageLister cachinglisters.ImageLister

// Sugared logger is easier to use but is not as performant as the
// raw logger. In performance critical paths, call logger.Desugar()
Expand All @@ -68,7 +74,9 @@ func NewController(
logger *zap.SugaredLogger,
kubeclientset kubernetes.Interface,
buildclientset clientset.Interface,
cachingclientset cachingclientset.Interface,
buildTemplateInformer informers.BuildTemplateInformer,
imageInformer cachinginformers.ImageInformer,
) *controller.Impl {

// Enrich the logs with controller name
Expand All @@ -77,7 +85,9 @@ func NewController(
r := &Reconciler{
kubeclientset: kubeclientset,
buildclientset: buildclientset,
cachingclientset: cachingclientset,
buildTemplatesLister: buildTemplateInformer.Lister(),
imageLister: imageInformer.Lister(),
Logger: logger,
}
impl := controller.NewImpl(r, logger, "BuildTemplates")
Expand Down
10 changes: 10 additions & 0 deletions pkg/reconciler/clusterbuildtemplate/clusterbuildtemplate.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ import (
buildscheme "github.com/knative/build/pkg/client/clientset/versioned/scheme"
informers "github.com/knative/build/pkg/client/informers/externalversions/build/v1alpha1"
listers "github.com/knative/build/pkg/client/listers/build/v1alpha1"
cachingclientset "github.com/knative/caching/pkg/client/clientset/versioned"
cachinginformers "github.com/knative/caching/pkg/client/informers/externalversions/caching/v1alpha1"
cachinglisters "github.com/knative/caching/pkg/client/listers/caching/v1alpha1"
)

const controllerAgentName = "clusterbuildtemplate-controller"
Expand All @@ -43,8 +46,11 @@ type Reconciler struct {
kubeclientset kubernetes.Interface
// buildclientset is a clientset for our own API group
buildclientset clientset.Interface
// cachingclientset is a clientset for creating caching resources.
cachingclientset cachingclientset.Interface

clusterBuildTemplatesLister listers.ClusterBuildTemplateLister
imageLister cachinglisters.ImageLister

// Sugared logger is easier to use but is not as performant as the
// raw logger. In performance critical paths, call logger.Desugar()
Expand All @@ -68,7 +74,9 @@ func NewController(
logger *zap.SugaredLogger,
kubeclientset kubernetes.Interface,
buildclientset clientset.Interface,
cachingclientset cachingclientset.Interface,
clusterBuildTemplateInformer informers.ClusterBuildTemplateInformer,
imageInformer cachinginformers.ImageInformer,
) *controller.Impl {

// Enrich the logs with controller name
Expand All @@ -77,7 +85,9 @@ func NewController(
r := &Reconciler{
kubeclientset: kubeclientset,
buildclientset: buildclientset,
cachingclientset: cachingclientset,
clusterBuildTemplatesLister: clusterBuildTemplateInformer.Lister(),
imageLister: imageInformer.Lister(),
Logger: logger,
}
impl := controller.NewImpl(r, logger, "ClusterBuildTemplates")
Expand Down
Loading