Skip to content

Commit

Permalink
Incorporate Build into Elafros.
Browse files Browse the repository at this point in the history
This copies over the Build type definitions and generates clients for them.

This incorporates BuildSpec into RevisionTemplate and BuildName into Revision.

A RevisionTemplate with a BuildSpec will stamp out a Build during reconciliation, and feed the resulting BuildName to the Revision.

The Revision will reflect the Build's progress in its Status, and stand up resources upon completion.

Fixes: #7
  • Loading branch information
mattmoor committed Jan 31, 2018
1 parent ccef227 commit 9ec03fd
Show file tree
Hide file tree
Showing 55 changed files with 2,986 additions and 75 deletions.
1 change: 1 addition & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
build --workspace_status_command=./print-workspace-status.sh
run --workspace_status_command=./print-workspace-status.sh
test --test_output=errors
14 changes: 11 additions & 3 deletions BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,10 @@ k8s_objects(
],
)

# All of our stuff goes here.
k8s_objects(
name = "everything",
name = "elafros",
objects = [
# We depend on Istio.
":istio",
":namespace",
":authz",
":crds",
Expand All @@ -97,3 +96,12 @@ k8s_objects(
":elawebhookservice",
],
)

k8s_objects(
name = "everything",
objects = [
":istio", # We depend on Istio.
# TODO(mattmoor): Add the Build stuff here once we can import it properly.
":elafros",
],
)
2 changes: 1 addition & 1 deletion hack/update-codegen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ CODEGEN_PKG=${CODEGEN_PKG:-$(cd ${SCRIPT_ROOT}; ls -d -1 ./vendor/k8s.io/code-ge
# instead of the $GOPATH directly. For normal projects this can be dropped.
${CODEGEN_PKG}/generate-groups.sh "deepcopy,client,informer,lister" \
github.com/google/elafros/pkg/client github.com/google/elafros/pkg/apis \
"ela:v1alpha1 istio:v1alpha2" \
"ela:v1alpha1 istio:v1alpha2 cloudbuild:v1alpha1" \
--go-header-file ${SCRIPT_ROOT}/hack/boilerplate/boilerplate.go.txt

# Make sure our dependencies are up-to-date
Expand Down
8 changes: 8 additions & 0 deletions pkg/apis/cloudbuild/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
load("@io_bazel_rules_go//go:def.bzl", "go_library")

go_library(
name = "go_default_library",
srcs = ["register.go"],
importpath = "github.com/google/elafros/pkg/apis/cloudbuild",
visibility = ["//visibility:public"],
)
21 changes: 21 additions & 0 deletions pkg/apis/cloudbuild/register.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
Copyright 2018 Google, Inc. All rights reserved.
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 cloudbuild

const (
GroupName = "cloudbuild.googleapis.com"
)
21 changes: 21 additions & 0 deletions pkg/apis/cloudbuild/v1alpha1/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
load("@io_bazel_rules_go//go:def.bzl", "go_library")

go_library(
name = "go_default_library",
srcs = [
"build_template_types.go",
"build_types.go",
"doc.go",
"register.go",
"zz_generated.deepcopy.go",
],
importpath = "github.com/google/elafros/pkg/apis/cloudbuild/v1alpha1",
visibility = ["//visibility:public"],
deps = [
"//pkg/apis/cloudbuild:go_default_library",
"//vendor/k8s.io/api/core/v1:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/runtime:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/runtime/schema:go_default_library",
],
)
93 changes: 93 additions & 0 deletions pkg/apis/cloudbuild/v1alpha1/build_template_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/*
Copyright 2018 Google, Inc. All rights reserved.
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 v1alpha1

import (
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// +genclient
// +genclient:noStatus
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

type BuildTemplate struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec BuildTemplateSpec `json:"spec"`
Status BuildTemplateStatus `json:"status"`
}

type BuildTemplateSpec struct {
// Parameters defines the parameters that can be populated in a template.
Parameters []ParameterSpec `json:"parameters,omitempty"`
Steps []corev1.Container `json:"steps"`
Volumes []corev1.Volume `json:"volumes"`
}

// BuildTemplateStatus is the status for a Build resource
type BuildTemplateStatus struct {
Conditions []BuildTemplateCondition `json:"conditions,omitempty"`
}

type BuildTemplateConditionType string

const (
// BuildTemplateInvalid specifies that the given specification is invalid.
BuildTemplateInvalid BuildTemplateConditionType = "Invalid"
)

// BuildTemplateCondition defines a readiness condition for a BuildTemplate.
// See: https://github.com/kubernetes/community/blob/master/contributors/devel/api-conventions.md#typical-status-properties
type BuildTemplateCondition struct {
Type BuildTemplateConditionType `json:"state"`

Status corev1.ConditionStatus `json:"status" description:"status of the condition, one of True, False, Unknown"`

// +optional
LastTransitionTime metav1.Time `json:"lastTransitionTime,omitempty" description:"last time the condition transit from one status to another"`

// +optional
Reason string `json:"reason,omitempty" description:"one-word CamelCase reason for the condition's last transition"`
// +optional
Message string `json:"message,omitempty" description:"human-readable message indicating details about last transition"`
}

// ParameterSpec defines the possible parameters that can be populated in a
// template.
type ParameterSpec struct {
// Name is the unique name of this template parameter.
Name string `json:"name"`

// Description is a human-readable explanation of this template parameter.
Description string `json:"description,omitempty"`

// Default, if specified, defines the default value that should be applied if
// the build does not specify the value for this parameter.
Default string `json:"default,omitempty"`
}

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

// BuildTemplateList is a list of BuildTemplate resources
type BuildTemplateList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata"`

Items []BuildTemplate `json:"items"`
}
159 changes: 159 additions & 0 deletions pkg/apis/cloudbuild/v1alpha1/build_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
/*
Copyright 2018 Google, Inc. All rights reserved.
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 v1alpha1

import (
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// +genclient
// +genclient:noStatus
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

// Build is a specification for a Build resource
type Build struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec BuildSpec `json:"spec"`
Status BuildStatus `json:"status"`
}

// BuildSpec is the spec for a Build resource
type BuildSpec struct {
Source *SourceSpec `json:"source,omitempty"`
Steps []corev1.Container `json:"steps,omitempty"`
// TODO(mattmoor): Remove Images
Images []string `json:"images,omitempty"`

Volumes []corev1.Volume `json:"volumes,omitempty"`

// Template, if specified,references a BuildTemplate resource to use to
// populate fields in the build, and optional Arguments to pass to the
// template.
Template *TemplateInstantiationSpec `json:"template,omitempty"`
}

type TemplateInstantiationSpec struct {
// Name references the BuildTemplate resource to use.
Name string `json:"name"`

// Namespace, if specified, is the namespace of the BuildTemplate resource to
// use. If omitted, the build's namespace is used.
Namespace string `json:"namespace,omitempty"`

// Arguments, if specified, lists values that should be applied to the
// parameters specified by the template.
Arguments []ArgumentSpec `json:"arguments,omitempty"`
}

// ArgumentSpec defines the actual values to use to populate a template's
// parameters.
type ArgumentSpec struct {
Name string `json:"name"`
Value string `json:"value"`
// TODO(jasonhall): ValueFrom?
}

// SourceSpec defines the input to the Build
type SourceSpec struct {
Git *GitSourceSpec `json:"git,omitempty"`
Custom *corev1.Container `json:"custom,omitempty"`
}

type GitSourceSpec struct {
Url string `json:"url"`

// One of these may be specified.
Branch string `json:"branch,omitempty"`
Tag string `json:"tag,omitempty"`
Ref string `json:"ref,omitempty"`
Commit string `json:"commit,omitempty"`

// TODO(mattmoor): authn/z
}

type BuildProvider string

const (
// GoogleBuildProvider indicates that this build was performed with Google Container Builder.
GoogleBuildProvider BuildProvider = "Google"
// ClusterBuildProvider indicates that this build was performed on-cluster.
ClusterBuildProvider BuildProvider = "Cluster"
)

// BuildStatus is the status for a Build resource
type BuildStatus struct {
Builder BuildProvider `json:"builder,omitempty"`

// Additional information based on the Builder executing this build.
Cluster *ClusterSpec `json:"cluster,omitempty"`
Google *GoogleSpec `json:"google,omitempty"`

// Information about the execution of the build.
StartTime metav1.Time `json:"startTime,omitEmpty"`
CompletionTime metav1.Time `json:"completionTime,omitEmpty"`

Conditions []BuildCondition `json:"conditions,omitempty"`
}

type ClusterSpec struct {
Namespace string `json:"namespace"`
JobName string `json:"jobName"`
}

type GoogleSpec struct {
Operation string `json:"operation"`
}

type BuildConditionType string

const (
// BuildComplete specifies that the build has completed successfully.
BuildComplete BuildConditionType = "Complete"
// BuildFailed specifies that the build has failed.
BuildFailed BuildConditionType = "Failed"
// BuildInvalid specifies that the given build specification is invalid.
BuildInvalid BuildConditionType = "Invalid"
)

// BuildCondition defines a readiness condition for a Build.
// See: https://github.com/kubernetes/community/blob/master/contributors/devel/api-conventions.md#typical-status-properties
type BuildCondition struct {
Type BuildConditionType `json:"state"`

Status corev1.ConditionStatus `json:"status" description:"status of the condition, one of True, False, Unknown"`

// +optional
LastTransitionTime metav1.Time `json:"lastTransitionTime,omitempty" description:"last time the condition transit from one status to another"`

// +optional
Reason string `json:"reason,omitempty" description:"one-word CamelCase reason for the condition's last transition"`
// +optional
Message string `json:"message,omitempty" description:"human-readable message indicating details about last transition"`
}

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

// BuildList is a list of Build resources
type BuildList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata"`

Items []Build `json:"items"`
}
21 changes: 21 additions & 0 deletions pkg/apis/cloudbuild/v1alpha1/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
Copyright 2018 Google, Inc. All rights reserved.
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.
*/

// +k8s:deepcopy-gen=package

// Package v1alpha1 is the v1alpha1 version of the API.
// +groupName=cloudbuild.googleapis.com
package v1alpha1
Loading

0 comments on commit 9ec03fd

Please sign in to comment.