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] Add continuous integration models (Projects and Builds) #1612

Closed
wants to merge 1 commit into from
Closed
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@ Thumbs.db

csrf_headers.txt
/dashboard
/build-maker
13 changes: 13 additions & 0 deletions base/200-clusterrole-tenant.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,20 @@ rules:
- apiGroups:
- dashboard.tekton.dev
resources:
- builds
- builds/status
- extensions
- projects
- projects/status
verbs:
- get
- list
- watch
- apiGroups:
- extensions
- apps
resources:
- ingresses
verbs:
- get
- list
Expand Down
59 changes: 59 additions & 0 deletions base/202-build-crd.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Copyright 2019 The Tekton 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.

---
apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
name: builds.dashboard.tekton.dev
labels:
app.kubernetes.io/component: dashboard
app.kubernetes.io/instance: default
app.kubernetes.io/part-of: tekton-dashboard
spec:
group: dashboard.tekton.dev
versions:
- name: v1alpha1
served: true
storage: true
preserveUnknownFields: false
validation:
openAPIV3Schema:
type: object
# One can use x-kubernetes-preserve-unknown-fields: true at the root
# of the schema (and inside any properties, additionalProperties)
# to get the traditional CRD behaviour that nothing is pruned, despite
# setting spec.preserveUnknownProperties: false.
#
# See https://kubernetes.io/blog/2019/06/20/crd-structural-schema/
# See issue: https://github.com/knative/serving/issues/912
x-kubernetes-preserve-unknown-fields: true
names:
kind: Build
plural: builds
categories:
- tekton
- tekton-dashboard
scope: Namespaced
# additionalPrinterColumns:
# - name: Repository URL
# type: string
# JSONPath: .spec.repositoryUrl
# - name: Age
# type: date
# JSONPath: .metadata.creationTimestamp
# Opt into the status subresource so metadata.generation
# starts to increment
subresources:
status: {}
64 changes: 64 additions & 0 deletions base/202-project-crd.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# Copyright 2019 The Tekton 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.

---
apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
name: projects.dashboard.tekton.dev
labels:
app.kubernetes.io/component: dashboard
app.kubernetes.io/instance: default
app.kubernetes.io/part-of: tekton-dashboard
spec:
group: dashboard.tekton.dev
versions:
- name: v1alpha1
served: true
storage: true
preserveUnknownFields: false
validation:
openAPIV3Schema:
type: object
# One can use x-kubernetes-preserve-unknown-fields: true at the root
# of the schema (and inside any properties, additionalProperties)
# to get the traditional CRD behaviour that nothing is pruned, despite
# setting spec.preserveUnknownProperties: false.
#
# See https://kubernetes.io/blog/2019/06/20/crd-structural-schema/
# See issue: https://github.com/knative/serving/issues/912
x-kubernetes-preserve-unknown-fields: true
names:
kind: Project
plural: projects
categories:
- tekton
- tekton-dashboard
shortNames:
- project
scope: Namespaced
additionalPrinterColumns:
- name: Service account
type: string
JSONPath: .spec.serviceAccountName
- name: Ingress URL
type: string
JSONPath: .spec.ingress.host
- name: Age
type: date
JSONPath: .metadata.creationTimestamp
# Opt into the status subresource so metadata.generation
# starts to increment
subresources:
status: {}
16 changes: 16 additions & 0 deletions cmd/build-maker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@

FROM golang as goBuilder

ARG GOARCH=amd64

USER root
WORKDIR /work
COPY . .
RUN GO111MODULE=on CGO_ENABLED=0 GOOS=linux GOARCH=$GOARCH go build ./cmd/build-maker

FROM alpine

WORKDIR /work
COPY --from=goBuilder /work/build-maker .

ENTRYPOINT ["./build-maker"]
147 changes: 147 additions & 0 deletions cmd/build-maker/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
/*
Copyright 2019-2020 The Tekton 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 main

import (
"os"
"strings"

"github.com/spf13/pflag"
dashboardv1alpha1 "github.com/tektoncd/dashboard/pkg/apis/dashboard/v1alpha1"
dashboardclientset "github.com/tektoncd/dashboard/pkg/client/clientset/versioned"
"github.com/tektoncd/dashboard/pkg/logging"
pipelinev1beta1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1"
resourcev1alpha1 "github.com/tektoncd/pipeline/pkg/apis/resource/v1alpha1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/yaml"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"
)

var (
kubeConfigPath = pflag.String("kube-config", "", "Path to kube config file")
file = pflag.String("file", "", "PipelineRun spec file")
namespace = pflag.String("namespace", "", "Target namespace")
ownerName = pflag.String("owner-name", "", "Owner project name")
ownerUid = pflag.String("owner-uid", "", "Owner project UID")
url = pflag.String("url", "", "Repository url")
revision = pflag.String("revision", "", "Revision")
logLevel = pflag.String("log-level", "info", "Minimum log level output by the logger")
logFormat = pflag.String("log-format", "json", "Format for log output (json or console)")
params = pflag.StringArray("param", nil, "Param int the form name=value")
)

func main() {
pflag.Parse()

logging.InitLogger(*logLevel, *logFormat)

if *file == "" {
logging.Log.Panic("file must be provided")
}

if *namespace == "" {
logging.Log.Panic("namespace must be provided")
}

if *url == "" {
logging.Log.Panic("url must be provided")
}

if *revision == "" {
logging.Log.Panic("revision must be provided")
}

if f, err := os.Open(*file); err != nil {
logging.Log.Panicf("Error loading file (%s): %s", *file, err.Error())
} else {
decoder := yaml.NewYAMLOrJSONDecoder(f, 4096)

var pipelineSpec pipelinev1beta1.PipelineSpec

if err := decoder.Decode(&pipelineSpec); err != nil {
logging.Log.Panicf("Error decoding file: %s", err.Error())
}

var cfg *rest.Config

if *kubeConfigPath != "" {
cfg, err = clientcmd.BuildConfigFromFlags("", *kubeConfigPath)
if err != nil {
logging.Log.Panicf("Error building kubeconfig from %s: %s", *kubeConfigPath, err.Error())
}
} else {
if cfg, err = rest.InClusterConfig(); err != nil {
logging.Log.Panicf("Error building kubeconfig: %s", err.Error())
}
}

dashboardClient, err := dashboardclientset.NewForConfig(cfg)
if err != nil {
logging.Log.Panicf("Error building dashboard clientset: %s", err.Error())
}

build := &dashboardv1alpha1.Build{
Spec: dashboardv1alpha1.BuildSpec{
PipelineSpec: pipelineSpec,
PipelineResourceSpec: resourcev1alpha1.PipelineResourceSpec{
Type: "git",
Params: []resourcev1alpha1.ResourceParam{
{
Name: "url",
Value: *url,
},
{
Name: "revision",
Value: *revision,
},
},
},
},
}

if params != nil {
for _, param := range *params {
nameValue := strings.Split(param, "=")
if len(nameValue) == 2 {
build.Spec.Params = append(build.Spec.Params, pipelinev1beta1.Param{
Name: nameValue[0],
Value: pipelinev1beta1.NewArrayOrString(nameValue[1]),
})
}
}
}

build.GenerateName = "build-"

if *ownerName != "" && *ownerUid != "" {
trueHelper := true
build.OwnerReferences = append(build.OwnerReferences, metav1.OwnerReference{
APIVersion: "dashboard.tekton.dev/v1alpha1",
Kind: "Project",
Name: *ownerName,
UID: types.UID(*ownerUid),
Controller: &trueHelper,
BlockOwnerDeletion: &trueHelper,
})
}

if build, err := dashboardClient.DashboardV1alpha1().Builds(*namespace).Create(build); err != nil {
logging.Log.Panicf("Error creating build: %s", err.Error())
} else {
logging.Log.Infof("Created build %s in namespace %s", build.Name, build.Namespace)
}
}
}
11 changes: 10 additions & 1 deletion cmd/dashboard/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
"github.com/tektoncd/dashboard/pkg/router"
pipelineclientset "github.com/tektoncd/pipeline/pkg/client/clientset/versioned"
resourceclientset "github.com/tektoncd/pipeline/pkg/client/resource/clientset/versioned"
triggersclientset "github.com/tektoncd/triggers/pkg/client/clientset/versioned"
k8sclientset "k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"
Expand Down Expand Up @@ -102,6 +103,11 @@ func main() {
logging.Log.Errorf("Error building pipeline clientset: %s", err.Error())
}

triggersClient, err := triggersclientset.NewForConfig(cfg)
if err != nil {
logging.Log.Errorf("Error building triggers clientset: %s", err.Error())
}

dashboardClient, err := dashboardclientset.NewForConfig(cfg)
if err != nil {
logging.Log.Errorf("Error building dashboard clientset: %s", err.Error())
Expand Down Expand Up @@ -147,6 +153,7 @@ func main() {
DashboardClient: dashboardClient,
PipelineClient: pipelineClient,
PipelineResourceClient: pipelineResourceClient,
TriggersClient: triggersClient,
K8sClient: k8sClient,
RouteClient: routeClient,
Options: options,
Expand All @@ -160,7 +167,9 @@ func main() {
resyncDur := time.Second * 30
controllers.StartTektonControllers(resource.PipelineClient, resource.PipelineResourceClient, *tenantNamespace, resyncDur, ctx.Done())
controllers.StartKubeControllers(resource.K8sClient, resyncDur, *tenantNamespace, *readOnly, routerHandler, ctx.Done())
controllers.StartDashboardControllers(resource.DashboardClient, resyncDur, *tenantNamespace, ctx.Done())
controllers.StartDashboardControllers(resource.DashboardClient, resource.TriggersClient, resource.K8sClient, resyncDur, *tenantNamespace, ctx.Done())

controllers.StartRuntimeControllers(cfg)

logging.Log.Infof("Creating server and entering wait loop")
CSRF := csrf.Protect(
Expand Down
9 changes: 5 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,21 @@ replace (
)

require (
github.com/circonus-labs/circonus-gometrics v2.3.1+incompatible
github.com/emicklei/go-restful v2.12.0+incompatible
github.com/google/go-cmp v0.4.0
github.com/gorilla/csrf v1.7.0
github.com/gorilla/websocket v1.4.2
github.com/openshift/api v3.9.0+incompatible // indirect
github.com/openshift/client-go v0.0.0-20191125132246-f6563a70e19a
github.com/spf13/pflag v1.0.5
github.com/tektoncd/pipeline v0.12.1
github.com/tektoncd/plumbing v0.0.0-20200430135134-e53521e1d887
github.com/tektoncd/triggers v0.6.0
go.uber.org/zap v1.15.0
k8s.io/api v0.17.6
k8s.io/apimachinery v0.17.6
k8s.io/api v0.18.2
k8s.io/apimachinery v0.18.2
k8s.io/client-go v11.0.1-0.20190805182717-6502b5e7b1b5+incompatible
k8s.io/code-generator v0.18.0
knative.dev/pkg v0.0.0-20200529164702-389d28f9b67a
sigs.k8s.io/yaml v1.2.0 // indirect
sigs.k8s.io/controller-runtime v0.5.0
)
Loading