...

Source file src/github.com/fluxcd/source-controller/api/v1/artifact_types.go

Documentation: github.com/fluxcd/source-controller/api/v1

     1  /*
     2  Copyright 2023 The Flux authors
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package v1
    18  
    19  import (
    20  	"path"
    21  	"strings"
    22  
    23  	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
    24  )
    25  
    26  // Artifact represents the output of a Source reconciliation.
    27  type Artifact struct {
    28  	// Path is the relative file path of the Artifact. It can be used to locate
    29  	// the file in the root of the Artifact storage on the local file system of
    30  	// the controller managing the Source.
    31  	// +required
    32  	Path string `json:"path"`
    33  
    34  	// URL is the HTTP address of the Artifact as exposed by the controller
    35  	// managing the Source. It can be used to retrieve the Artifact for
    36  	// consumption, e.g. by another controller applying the Artifact contents.
    37  	// +required
    38  	URL string `json:"url"`
    39  
    40  	// Revision is a human-readable identifier traceable in the origin source
    41  	// system. It can be a Git commit SHA, Git tag, a Helm chart version, etc.
    42  	// +required
    43  	Revision string `json:"revision"`
    44  
    45  	// Digest is the digest of the file in the form of '<algorithm>:<checksum>'.
    46  	// +optional
    47  	// +kubebuilder:validation:Pattern="^[a-z0-9]+(?:[.+_-][a-z0-9]+)*:[a-zA-Z0-9=_-]+$"
    48  	Digest string `json:"digest,omitempty"`
    49  
    50  	// LastUpdateTime is the timestamp corresponding to the last update of the
    51  	// Artifact.
    52  	// +required
    53  	LastUpdateTime metav1.Time `json:"lastUpdateTime"`
    54  
    55  	// Size is the number of bytes in the file.
    56  	// +optional
    57  	Size *int64 `json:"size,omitempty"`
    58  
    59  	// Metadata holds upstream information such as OCI annotations.
    60  	// +optional
    61  	Metadata map[string]string `json:"metadata,omitempty"`
    62  }
    63  
    64  // HasRevision returns if the given revision matches the current Revision of
    65  // the Artifact.
    66  func (in *Artifact) HasRevision(revision string) bool {
    67  	if in == nil {
    68  		return false
    69  	}
    70  	return in.Revision == revision
    71  }
    72  
    73  // HasDigest returns if the given digest matches the current Digest of the
    74  // Artifact.
    75  func (in *Artifact) HasDigest(digest string) bool {
    76  	if in == nil {
    77  		return false
    78  	}
    79  	return in.Digest == digest
    80  }
    81  
    82  // ArtifactDir returns the artifact dir path in the form of
    83  // '<kind>/<namespace>/<name>'.
    84  func ArtifactDir(kind, namespace, name string) string {
    85  	kind = strings.ToLower(kind)
    86  	return path.Join(kind, namespace, name)
    87  }
    88  
    89  // ArtifactPath returns the artifact path in the form of
    90  // '<kind>/<namespace>/name>/<filename>'.
    91  func ArtifactPath(kind, namespace, name, filename string) string {
    92  	return path.Join(ArtifactDir(kind, namespace, name), filename)
    93  }
    94  

View as plain text