Skip to content

Commit

Permalink
API changes
Browse files Browse the repository at this point in the history
- Make Build.Spec.Source optional
- Rename Build.Spec.Source.GitSource to Git (go-type only)
- Rename Build.Spec.Source.LocalSource to Local (go-type only)
- Rename BuildRun.Spec.Build.Build to Spec (go-type only)
- Rename BuildRun.Spec.Source.LocalSource to Local (go-type only)
- Remove the undocumented CONTEXT_DIR parameter
- Remove the undocumented `build.output.image` and `build.source.contextDir` replacement variables
- Declare Build.Spec.Source.Type as required
- Declare BuildRun.Spec.Source.Type as required
- Add missing documentation to API fields
  • Loading branch information
SaschaSchwarze0 committed Feb 27, 2024
1 parent 6ee1cd8 commit 467495d
Show file tree
Hide file tree
Showing 30 changed files with 313 additions and 301 deletions.
37 changes: 24 additions & 13 deletions deploy/crds/shipwright.io_buildruns.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6402,7 +6402,7 @@ spec:
description: 'Name of the referent; More info: http://kubernetes.io/docs/user-guide/identifiers#names'
type: string
spec:
description: Build refers to an embedded build specification
description: Spec refers to an embedded build specification
properties:
env:
description: Env contains additional environment variables
Expand Down Expand Up @@ -6695,7 +6695,8 @@ spec:
repo. Optional.
type: string
git:
description: GitSource
description: Git contains the details for the source of
type Git
properties:
cloneSecret:
description: CloneSecret references a Secret that
Expand All @@ -6714,7 +6715,8 @@ spec:
- url
type: object
local:
description: LocalSource
description: Local contains the details for the source
of type Local
properties:
name:
description: Name of the local step
Expand All @@ -6725,7 +6727,8 @@ spec:
type: string
type: object
ociArtifact:
description: OCIArtifact
description: OCIArtifact contains the details for the
source of type OCIArtifact
properties:
image:
description: Image reference, i.e. quay.io/org/image:tag
Expand All @@ -6746,8 +6749,10 @@ spec:
type: object
type:
description: Type is the BuildSource qualifier, the type
of the data-source.
of the source.
type: string
required:
- type
type: object
strategy:
description: Strategy references the BuildStrategy to use
Expand Down Expand Up @@ -8543,7 +8548,6 @@ spec:
type: array
required:
- output
- source
- strategy
type: object
type: object
Expand Down Expand Up @@ -8812,7 +8816,8 @@ spec:
this could only be a local source
properties:
local:
description: LocalSource
description: Local contains the details for the source of type
Local
properties:
name:
description: Name of the local step
Expand All @@ -8824,8 +8829,10 @@ spec:
type: object
type:
description: Type is the BuildRunSource qualifier, the type of
the data-source. Only LocalType is supported.
the source. Only Local is supported.
type: string
required:
- type
type: object
state:
description: State is used for canceling a buildrun (and maybe more
Expand Down Expand Up @@ -10690,7 +10697,8 @@ spec:
Optional.
type: string
git:
description: GitSource
description: Git contains the details for the source of type
Git
properties:
cloneSecret:
description: CloneSecret references a Secret that contains
Expand All @@ -10708,7 +10716,8 @@ spec:
- url
type: object
local:
description: LocalSource
description: Local contains the details for the source of
type Local
properties:
name:
description: Name of the local step
Expand All @@ -10719,7 +10728,8 @@ spec:
type: string
type: object
ociArtifact:
description: OCIArtifact
description: OCIArtifact contains the details for the source
of type OCIArtifact
properties:
image:
description: Image reference, i.e. quay.io/org/image:tag
Expand All @@ -10740,8 +10750,10 @@ spec:
type: object
type:
description: Type is the BuildSource qualifier, the type of
the data-source.
the source.
type: string
required:
- type
type: object
strategy:
description: Strategy references the BuildStrategy to use to build
Expand Down Expand Up @@ -12461,7 +12473,6 @@ spec:
type: array
required:
- output
- source
- strategy
type: object
completionTime:
Expand Down
13 changes: 8 additions & 5 deletions deploy/crds/shipwright.io_builds.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2464,7 +2464,7 @@ spec:
description: ContextDir is a path to subfolder in the repo. Optional.
type: string
git:
description: GitSource
description: Git contains the details for the source of type Git
properties:
cloneSecret:
description: CloneSecret references a Secret that contains
Expand All @@ -2482,7 +2482,8 @@ spec:
- url
type: object
local:
description: LocalSource
description: Local contains the details for the source of type
Local
properties:
name:
description: Name of the local step
Expand All @@ -2493,7 +2494,8 @@ spec:
type: string
type: object
ociArtifact:
description: OCIArtifact
description: OCIArtifact contains the details for the source of
type OCIArtifact
properties:
image:
description: Image reference, i.e. quay.io/org/image:tag
Expand All @@ -2514,8 +2516,10 @@ spec:
type: object
type:
description: Type is the BuildSource qualifier, the type of the
data-source.
source.
type: string
required:
- type
type: object
strategy:
description: Strategy references the BuildStrategy to use to build
Expand Down Expand Up @@ -4174,7 +4178,6 @@ spec:
type: array
required:
- output
- source
- strategy
type: object
status:
Expand Down
77 changes: 39 additions & 38 deletions pkg/apis/build/v1beta1/build_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,6 @@ func (src *Build) ConvertTo(ctx context.Context, obj *unstructured.Unstructured)
alphaBuild.ObjectMeta.Annotations[v1alpha1.AnnotationBuildRunDeletion] = strconv.FormatBool(*src.Spec.Retention.AtBuildDeletion)
}

// convert OCIArtifact to Bundle
if src.Spec.Source.OCIArtifact != nil {
alphaBuild.Spec.Source.BundleContainer = &v1alpha1.BundleContainer{
Image: src.Spec.Source.OCIArtifact.Image,
Prune: (*v1alpha1.PruneOption)(src.Spec.Source.OCIArtifact.Prune),
}
}

mapito, err := runtime.DefaultUnstructuredConverter.ToUnstructured(&alphaBuild)
if err != nil {
ctxlog.Error(ctx, err, "failed structuring the newObject")
Expand Down Expand Up @@ -111,40 +103,44 @@ func (src *Build) ConvertFrom(ctx context.Context, obj *unstructured.Unstructure

func (dest *BuildSpec) ConvertFrom(orig *v1alpha1.BuildSpec) error {
// Handle BuildSpec Source
specSource := Source{}

// only interested on spec.sources as long as an item of the list
// is of the type LocalCopy. Otherwise, we move into bundle or git types.
index, isLocal := v1alpha1.IsLocalCopyType(orig.Sources)
if isLocal {
specSource.Type = LocalType
specSource.LocalSource = &Local{
Name: orig.Sources[index].Name,
Timeout: orig.Sources[index].Timeout,
dest.Source = &Source{
Type: LocalType,
Local: &Local{
Name: orig.Sources[index].Name,
Timeout: orig.Sources[index].Timeout,
},
ContextDir: orig.Source.ContextDir,
}
} else {
if orig.Source.BundleContainer != nil {
specSource.Type = OCIArtifactType
specSource.OCIArtifact = &OCIArtifact{
} else if orig.Source.BundleContainer != nil {
dest.Source = &Source{
Type: OCIArtifactType,
OCIArtifact: &OCIArtifact{
Image: orig.Source.BundleContainer.Image,
Prune: (*PruneOption)(orig.Source.BundleContainer.Prune),
}
if orig.Source.Credentials != nil {
specSource.OCIArtifact.PullSecret = &orig.Source.Credentials.Name
}
} else if orig.Source.URL != nil {
specSource.Type = GitType
specSource.GitSource = &Git{
},
ContextDir: orig.Source.ContextDir,
}
if orig.Source.Credentials != nil {
dest.Source.OCIArtifact.PullSecret = &orig.Source.Credentials.Name
}
} else if orig.Source.URL != nil {
dest.Source = &Source{
Type: GitType,
Git: &Git{
URL: *orig.Source.URL,
Revision: orig.Source.Revision,
}
if orig.Source.Credentials != nil {
specSource.GitSource.CloneSecret = &orig.Source.Credentials.Name
}
},
ContextDir: orig.Source.ContextDir,
}
if orig.Source.Credentials != nil {
dest.Source.Git.CloneSecret = &orig.Source.Credentials.Name
}
}
specSource.ContextDir = orig.Source.ContextDir
dest.Source = specSource

// Handle BuildSpec Triggers
if orig.Trigger != nil {
Expand Down Expand Up @@ -232,11 +228,11 @@ func (dest *BuildSpec) ConvertFrom(orig *v1alpha1.BuildSpec) error {

func (dest *BuildSpec) ConvertTo(bs *v1alpha1.BuildSpec) error {
// Handle BuildSpec Sources or Source
if dest.Source.Type == LocalType && dest.Source.LocalSource != nil {
if dest.Source != nil && dest.Source.Type == LocalType && dest.Source.Local != nil {
bs.Sources = append(bs.Sources, v1alpha1.BuildSource{
Name: dest.Source.LocalSource.Name,
Name: dest.Source.Local.Name,
Type: v1alpha1.LocalCopy,
Timeout: dest.Source.LocalSource.Timeout,
Timeout: dest.Source.Local.Timeout,
})
} else {
bs.Source = getAlphaBuildSource(*dest)
Expand Down Expand Up @@ -419,6 +415,11 @@ func convertToBetaTriggers(orig *v1alpha1.TriggerWhen) TriggerWhen {

func getAlphaBuildSource(src BuildSpec) v1alpha1.Source {
source := v1alpha1.Source{}

if src.Source == nil {
return source
}

var credentials corev1.LocalObjectReference
var revision *string

Expand All @@ -434,14 +435,14 @@ func getAlphaBuildSource(src BuildSpec) v1alpha1.Source {
Prune: (*v1alpha1.PruneOption)(src.Source.OCIArtifact.Prune),
}
default:
if src.Source.GitSource != nil && src.Source.GitSource.CloneSecret != nil {
if src.Source.Git != nil && src.Source.Git.CloneSecret != nil {
credentials = corev1.LocalObjectReference{
Name: *src.Source.GitSource.CloneSecret,
Name: *src.Source.Git.CloneSecret,
}
}
if src.Source.GitSource != nil {
source.URL = &src.Source.GitSource.URL
revision = src.Source.GitSource.Revision
if src.Source.Git != nil {
source.URL = &src.Source.Git.URL
revision = src.Source.Git.Revision
}

}
Expand Down
14 changes: 11 additions & 3 deletions pkg/apis/build/v1beta1/build_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,9 @@ type BuildSpec struct {
// Source refers to the location where the source code is,
// this could be a git repository, a local source or an oci
// artifact
Source Source `json:"source"`
//
// +optional
Source *Source `json:"source"`

// Trigger defines the scenarios where a new build should be triggered.
//
Expand All @@ -137,6 +139,7 @@ type BuildSpec struct {
Timeout *metav1.Duration `json:"timeout,omitempty"`

// Env contains additional environment variables that should be passed to the build container
//
// +optional
Env []corev1.EnvVar `json:"env,omitempty"`

Expand All @@ -147,6 +150,7 @@ type BuildSpec struct {

// Volumes contains volume Overrides of the BuildStrategy volumes in case those are allowed
// to be overridden. Must only contain volumes that exist in the corresponding BuildStrategy
//
// +optional
Volumes []BuildVolume `json:"volumes,omitempty"`
}
Expand Down Expand Up @@ -278,14 +282,18 @@ func init() {

// GetSourceCredentials returns the secret name for a Build Source
func (b Build) GetSourceCredentials() *string {
if b.Spec.Source == nil {
return nil
}

switch b.Spec.Source.Type {
case OCIArtifactType:
if b.Spec.Source.OCIArtifact != nil && b.Spec.Source.OCIArtifact.PullSecret != nil {
return b.Spec.Source.OCIArtifact.PullSecret
}
default:
if b.Spec.Source.GitSource != nil && b.Spec.Source.GitSource.CloneSecret != nil {
return b.Spec.Source.GitSource.CloneSecret
if b.Spec.Source.Git != nil && b.Spec.Source.Git.CloneSecret != nil {
return b.Spec.Source.Git.CloneSecret
}
}
return nil
Expand Down
Loading

0 comments on commit 467495d

Please sign in to comment.