Skip to content

Commit

Permalink
Unify Go struct field names with YAML/JSON field names
Browse files Browse the repository at this point in the history
  • Loading branch information
imjasonh committed Mar 22, 2021
1 parent 0430ccc commit 3b305c1
Show file tree
Hide file tree
Showing 26 changed files with 278 additions and 300 deletions.
38 changes: 21 additions & 17 deletions pkg/apis/build/v1alpha1/build_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,52 +65,56 @@ const (
type BuildSpec struct {
// Source refers to the Git repository containing the
// source code to be built.
Source GitSource `json:"source"`
Source Source `json:"source"`

// StrategyRef refers to the BuildStrategy to be used to
// build the container image.
// There are namespaced scope and cluster scope BuildStrategy
StrategyRef *StrategyRef `json:"strategy"`
// Strategy references the BuildStrategy to use to build the container
// image.
Strategy *Strategy `json:"strategy"`

// BuilderImage refers to the image containing the build tools
// inside which the source code would be built.
// Builder refers to the image containing the build tools inside which
// the source code would be built.
//
// +optional
BuilderImage *Image `json:"builder,omitempty"`
Builder *Image `json:"builder,omitempty"`

// Dockerfile is the path to the Dockerfile to be used for
// build strategies which bank on the Dockerfile for building
// an image.
//
// +optional
Dockerfile *string `json:"dockerfile,omitempty"`

// Parameters contains name-value that could be used to loosely
// type parameters in the BuildStrategy.
//
// +optional
Parameters *[]Parameter `json:"parameters,omitempty"`

// Runtime represents the runtime-image
// Runtime represents the runtime-image.
//
// +optional
Runtime *Runtime `json:"runtime,omitempty"`

// Output refers to the location where the generated
// image would be pushed to.
// Output refers to the location where the built image would be pushed.
Output Image `json:"output"`

// Timeout defines the maximum run time of a build run.
// Timeout defines the maximum amount of time the Build should take to execute.
//
// +optional
// +kubebuilder:validation:Format=duration
Timeout *metav1.Duration `json:"timeout,omitempty"`
}

// Image refers to an container image with credentials
type Image struct {
// ImageURL is the URL where the image will be pushed to.
ImageURL string `json:"image"`
// Image is the reference of the image.
Image string `json:"image"`

// SecretRef is a reference to the Secret containing the
// credentials to push the image to the registry
// Credentials references a Secret that contains credentials to access
// the image registry.
//
// +optional
SecretRef *corev1.LocalObjectReference `json:"credentials,omitempty"`
Credentials *corev1.LocalObjectReference `json:"credentials,omitempty"`
}

// Runtime represents the runtime-image, created using parts of builder-image, and a different
Expand Down
1 change: 0 additions & 1 deletion pkg/apis/build/v1alpha1/buildrun_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ const (

// BuildRunSpec defines the desired state of BuildRun
type BuildRunSpec struct {

// BuildRef refers to the Build
BuildRef *BuildRef `json:"buildRef"`

Expand Down
4 changes: 2 additions & 2 deletions pkg/apis/build/v1alpha1/buildstrategy.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ type BuildStrategyStatus struct {
// BuildStrategyKind defines the type of BuildStrategy used by the build.
type BuildStrategyKind string

// StrategyRef can be used to refer to a specific instance of a buildstrategy.
// Strategy can be used to refer to a specific instance of a buildstrategy.
// Copied from CrossVersionObjectReference: https://github.com/kubernetes/kubernetes/blob/169df7434155cbbc22f1532cba8e0a9588e29ad8/pkg/apis/autoscaling/types.go#L64
type StrategyRef struct {
type Strategy struct {
// Name of the referent; More info: http://kubernetes.io/docs/user-guide/identifiers#names
Name string `json:"name"`

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,30 @@ import (
corev1 "k8s.io/api/core/v1"
)

// GitSource contains the versioned source code metadata
// This is similar to OpenShift BuildConfig Git Source API
type GitSource struct {

// URL of the git repo
// Source describes the Git source repository to fetch.
type Source struct {
// URL describes the URL of the Git repository.
URL string `json:"url"`

// Ref is a git reference. Optional. If not defined, it will fallback to the git repository default branch.
// Revision describes the Git revision (e.g., branch, tag, commit SHA,
// etc.) to fetch.
//
// If not defined, it will fallback to the repository's default branch.
//
// +optional
Revision *string `json:"revision,omitempty"`

// ContextDir is a path to subfolder in the repo. Optional.
//
// +optional
ContextDir *string `json:"contextDir,omitempty"`

// Credentials references a Secret that contains credentials to access
// the repository.
//
// +optional
Credentials *corev1.LocalObjectReference `json:"credentials,omitempty"`

// HTTPProxy is optional.
HTTPProxy string `json:"httpProxy,omitempty"`

Expand All @@ -31,9 +41,6 @@ type GitSource struct {
// NoProxy can be used to specify domains for which no proxying should be performed. Optional.
NoProxy string `json:"noProxy,omitempty"`

// SecretRef refers to the secret that contains credentials to access the git repo. Optional.
SecretRef *corev1.LocalObjectReference `json:"credentials,omitempty"`

// Flavor of the git provider like github, gitlab, bitbucket, generic, etc. Optional.
Flavor string `json:"flavor,omitempty"`
}
84 changes: 42 additions & 42 deletions pkg/apis/build/v1alpha1/zz_generated.deepcopy.go

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

31 changes: 0 additions & 31 deletions pkg/apis/build/v1alpha1/zz_generated.openapi.go

This file was deleted.

2 changes: 1 addition & 1 deletion pkg/reconciler/build/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func (r *ReconcileBuild) Reconcile(request reconcile.Request) (reconcile.Result,
}

// Increase Build count in metrics
buildmetrics.BuildCountInc(b.Spec.StrategyRef.Name, b.Namespace, b.Name)
buildmetrics.BuildCountInc(b.Spec.Strategy.Name, b.Namespace, b.Name)

ctxlog.Debug(ctx, "finishing reconciling Build", namespace, request.Namespace, name, request.Name)
return reconcile.Result{}, nil
Expand Down
30 changes: 15 additions & 15 deletions pkg/reconciler/build/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,10 @@ var _ = Describe("Reconcile Build", func() {
Describe("Reconcile", func() {
Context("when source secret is specified", func() {
It("fails when the secret does not exist", func() {
buildSample.Spec.Source.SecretRef = &corev1.LocalObjectReference{
buildSample.Spec.Source.Credentials = &corev1.LocalObjectReference{
Name: "non-existing",
}
buildSample.Spec.Output.SecretRef = nil
buildSample.Spec.Output.Credentials = nil

statusCall := ctl.StubFunc(corev1.ConditionFalse, build.SpecSourceSecretRefNotFound, "referenced secret non-existing not found")
statusWriter.UpdateCalls(statusCall)
Expand All @@ -98,10 +98,10 @@ var _ = Describe("Reconcile Build", func() {
})

It("succeeds when the secret exists foobar", func() {
buildSample.Spec.Source.SecretRef = &corev1.LocalObjectReference{
buildSample.Spec.Source.Credentials = &corev1.LocalObjectReference{
Name: "existing",
}
buildSample.Spec.Output.SecretRef = nil
buildSample.Spec.Output.Credentials = nil

// Fake some client Get calls and ensure we populate all
// different resources we could get during reconciliation
Expand Down Expand Up @@ -130,13 +130,13 @@ var _ = Describe("Reconcile Build", func() {

Context("when builder image secret is specified", func() {
It("fails when the secret does not exist", func() {
buildSample.Spec.BuilderImage = &build.Image{
ImageURL: "busybox",
SecretRef: &corev1.LocalObjectReference{
buildSample.Spec.Builder = &build.Image{
Image: "busybox",
Credentials: &corev1.LocalObjectReference{
Name: "non-existing",
},
}
buildSample.Spec.Output.SecretRef = nil
buildSample.Spec.Output.Credentials = nil

statusCall := ctl.StubFunc(corev1.ConditionFalse, build.SpecBuilderSecretRefNotFound, "referenced secret non-existing not found")
statusWriter.UpdateCalls(statusCall)
Expand All @@ -147,13 +147,13 @@ var _ = Describe("Reconcile Build", func() {
})

It("succeeds when the secret exists", func() {
buildSample.Spec.BuilderImage = &build.Image{
ImageURL: "busybox",
SecretRef: &corev1.LocalObjectReference{
buildSample.Spec.Builder = &build.Image{
Image: "busybox",
Credentials: &corev1.LocalObjectReference{
Name: "existing",
},
}
buildSample.Spec.Output.SecretRef = nil
buildSample.Spec.Output.Credentials = nil

// Fake some client Get calls and ensure we populate all
// different resources we could get during reconciliation
Expand Down Expand Up @@ -218,10 +218,10 @@ var _ = Describe("Reconcile Build", func() {

Context("when source secret and output secret are specified", func() {
It("fails when both secrets do not exist", func() {
buildSample.Spec.Source.SecretRef = &corev1.LocalObjectReference{
buildSample.Spec.Source.Credentials = &corev1.LocalObjectReference{
Name: "non-existing-source",
}
buildSample.Spec.Output.SecretRef = &corev1.LocalObjectReference{
buildSample.Spec.Output.Credentials = &corev1.LocalObjectReference{
Name: "non-existing-output",
}

Expand Down Expand Up @@ -453,7 +453,7 @@ var _ = Describe("Reconcile Build", func() {
It("succeed when source URL is fake private URL because build reference a sourceURL secret", func() {
buildSample := ctl.BuildWithClusterBuildStrategyAndSourceSecret(buildName, namespace, buildStrategyName)
buildSample.Spec.Source.URL = "https://github.yourco.com/org/build-fake"
buildSample.Spec.Source.SecretRef.Name = registrySecret
buildSample.Spec.Source.Credentials.Name = registrySecret

// Fake some client Get calls and ensure we populate all
// different resources we could get during reconciliation
Expand Down
Loading

0 comments on commit 3b305c1

Please sign in to comment.