...

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

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

     1  /*
     2  Copyright 2024 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  	"time"
    21  
    22  	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
    23  
    24  	"github.com/fluxcd/pkg/apis/meta"
    25  )
    26  
    27  // HelmChartKind is the string representation of a HelmChart.
    28  const HelmChartKind = "HelmChart"
    29  
    30  // HelmChartSpec specifies the desired state of a Helm chart.
    31  type HelmChartSpec struct {
    32  	// Chart is the name or path the Helm chart is available at in the
    33  	// SourceRef.
    34  	// +required
    35  	Chart string `json:"chart"`
    36  
    37  	// Version is the chart version semver expression, ignored for charts from
    38  	// GitRepository and Bucket sources. Defaults to latest when omitted.
    39  	// +kubebuilder:default:=*
    40  	// +optional
    41  	Version string `json:"version,omitempty"`
    42  
    43  	// SourceRef is the reference to the Source the chart is available at.
    44  	// +required
    45  	SourceRef LocalHelmChartSourceReference `json:"sourceRef"`
    46  
    47  	// Interval at which the HelmChart SourceRef is checked for updates.
    48  	// This interval is approximate and may be subject to jitter to ensure
    49  	// efficient use of resources.
    50  	// +kubebuilder:validation:Type=string
    51  	// +kubebuilder:validation:Pattern="^([0-9]+(\\.[0-9]+)?(ms|s|m|h))+$"
    52  	// +required
    53  	Interval metav1.Duration `json:"interval"`
    54  
    55  	// ReconcileStrategy determines what enables the creation of a new artifact.
    56  	// Valid values are ('ChartVersion', 'Revision').
    57  	// See the documentation of the values for an explanation on their behavior.
    58  	// Defaults to ChartVersion when omitted.
    59  	// +kubebuilder:validation:Enum=ChartVersion;Revision
    60  	// +kubebuilder:default:=ChartVersion
    61  	// +optional
    62  	ReconcileStrategy string `json:"reconcileStrategy,omitempty"`
    63  
    64  	// ValuesFiles is an alternative list of values files to use as the chart
    65  	// values (values.yaml is not included by default), expected to be a
    66  	// relative path in the SourceRef.
    67  	// Values files are merged in the order of this list with the last file
    68  	// overriding the first. Ignored when omitted.
    69  	// +optional
    70  	ValuesFiles []string `json:"valuesFiles,omitempty"`
    71  
    72  	// IgnoreMissingValuesFiles controls whether to silently ignore missing values
    73  	// files rather than failing.
    74  	// +optional
    75  	IgnoreMissingValuesFiles bool `json:"ignoreMissingValuesFiles,omitempty"`
    76  
    77  	// Suspend tells the controller to suspend the reconciliation of this
    78  	// source.
    79  	// +optional
    80  	Suspend bool `json:"suspend,omitempty"`
    81  
    82  	// Verify contains the secret name containing the trusted public keys
    83  	// used to verify the signature and specifies which provider to use to check
    84  	// whether OCI image is authentic.
    85  	// This field is only supported when using HelmRepository source with spec.type 'oci'.
    86  	// Chart dependencies, which are not bundled in the umbrella chart artifact, are not verified.
    87  	// +optional
    88  	Verify *OCIRepositoryVerification `json:"verify,omitempty"`
    89  }
    90  
    91  const (
    92  	// ReconcileStrategyChartVersion reconciles when the version of the Helm chart is different.
    93  	ReconcileStrategyChartVersion string = "ChartVersion"
    94  
    95  	// ReconcileStrategyRevision reconciles when the Revision of the source is different.
    96  	ReconcileStrategyRevision string = "Revision"
    97  )
    98  
    99  // LocalHelmChartSourceReference contains enough information to let you locate
   100  // the typed referenced object at namespace level.
   101  type LocalHelmChartSourceReference struct {
   102  	// APIVersion of the referent.
   103  	// +optional
   104  	APIVersion string `json:"apiVersion,omitempty"`
   105  
   106  	// Kind of the referent, valid values are ('HelmRepository', 'GitRepository',
   107  	// 'Bucket').
   108  	// +kubebuilder:validation:Enum=HelmRepository;GitRepository;Bucket
   109  	// +required
   110  	Kind string `json:"kind"`
   111  
   112  	// Name of the referent.
   113  	// +required
   114  	Name string `json:"name"`
   115  }
   116  
   117  // HelmChartStatus records the observed state of the HelmChart.
   118  type HelmChartStatus struct {
   119  	// ObservedGeneration is the last observed generation of the HelmChart
   120  	// object.
   121  	// +optional
   122  	ObservedGeneration int64 `json:"observedGeneration,omitempty"`
   123  
   124  	// ObservedSourceArtifactRevision is the last observed Artifact.Revision
   125  	// of the HelmChartSpec.SourceRef.
   126  	// +optional
   127  	ObservedSourceArtifactRevision string `json:"observedSourceArtifactRevision,omitempty"`
   128  
   129  	// ObservedChartName is the last observed chart name as specified by the
   130  	// resolved chart reference.
   131  	// +optional
   132  	ObservedChartName string `json:"observedChartName,omitempty"`
   133  
   134  	// ObservedValuesFiles are the observed value files of the last successful
   135  	// reconciliation.
   136  	// It matches the chart in the last successfully reconciled artifact.
   137  	// +optional
   138  	ObservedValuesFiles []string `json:"observedValuesFiles,omitempty"`
   139  
   140  	// Conditions holds the conditions for the HelmChart.
   141  	// +optional
   142  	Conditions []metav1.Condition `json:"conditions,omitempty"`
   143  
   144  	// URL is the dynamic fetch link for the latest Artifact.
   145  	// It is provided on a "best effort" basis, and using the precise
   146  	// BucketStatus.Artifact data is recommended.
   147  	// +optional
   148  	URL string `json:"url,omitempty"`
   149  
   150  	// Artifact represents the output of the last successful reconciliation.
   151  	// +optional
   152  	Artifact *Artifact `json:"artifact,omitempty"`
   153  
   154  	meta.ReconcileRequestStatus `json:",inline"`
   155  }
   156  
   157  const (
   158  	// ChartPullSucceededReason signals that the pull of the Helm chart
   159  	// succeeded.
   160  	ChartPullSucceededReason string = "ChartPullSucceeded"
   161  
   162  	// ChartPackageSucceededReason signals that the package of the Helm
   163  	// chart succeeded.
   164  	ChartPackageSucceededReason string = "ChartPackageSucceeded"
   165  )
   166  
   167  // GetConditions returns the status conditions of the object.
   168  func (in HelmChart) GetConditions() []metav1.Condition {
   169  	return in.Status.Conditions
   170  }
   171  
   172  // SetConditions sets the status conditions on the object.
   173  func (in *HelmChart) SetConditions(conditions []metav1.Condition) {
   174  	in.Status.Conditions = conditions
   175  }
   176  
   177  // GetRequeueAfter returns the duration after which the source must be
   178  // reconciled again.
   179  func (in HelmChart) GetRequeueAfter() time.Duration {
   180  	return in.Spec.Interval.Duration
   181  }
   182  
   183  // GetArtifact returns the latest artifact from the source if present in the
   184  // status sub-resource.
   185  func (in *HelmChart) GetArtifact() *Artifact {
   186  	return in.Status.Artifact
   187  }
   188  
   189  // GetValuesFiles returns a merged list of HelmChartSpec.ValuesFiles.
   190  func (in *HelmChart) GetValuesFiles() []string {
   191  	return in.Spec.ValuesFiles
   192  }
   193  
   194  // +genclient
   195  // +kubebuilder:storageversion
   196  // +kubebuilder:object:root=true
   197  // +kubebuilder:resource:shortName=hc
   198  // +kubebuilder:subresource:status
   199  // +kubebuilder:printcolumn:name="Chart",type=string,JSONPath=`.spec.chart`
   200  // +kubebuilder:printcolumn:name="Version",type=string,JSONPath=`.spec.version`
   201  // +kubebuilder:printcolumn:name="Source Kind",type=string,JSONPath=`.spec.sourceRef.kind`
   202  // +kubebuilder:printcolumn:name="Source Name",type=string,JSONPath=`.spec.sourceRef.name`
   203  // +kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp",description=""
   204  // +kubebuilder:printcolumn:name="Ready",type="string",JSONPath=".status.conditions[?(@.type==\"Ready\")].status",description=""
   205  // +kubebuilder:printcolumn:name="Status",type="string",JSONPath=".status.conditions[?(@.type==\"Ready\")].message",description=""
   206  
   207  // HelmChart is the Schema for the helmcharts API.
   208  type HelmChart struct {
   209  	metav1.TypeMeta   `json:",inline"`
   210  	metav1.ObjectMeta `json:"metadata,omitempty"`
   211  
   212  	Spec HelmChartSpec `json:"spec,omitempty"`
   213  	// +kubebuilder:default={"observedGeneration":-1}
   214  	Status HelmChartStatus `json:"status,omitempty"`
   215  }
   216  
   217  // HelmChartList contains a list of HelmChart objects.
   218  // +kubebuilder:object:root=true
   219  type HelmChartList struct {
   220  	metav1.TypeMeta `json:",inline"`
   221  	metav1.ListMeta `json:"metadata,omitempty"`
   222  	Items           []HelmChart `json:"items"`
   223  }
   224  
   225  func init() {
   226  	SchemeBuilder.Register(&HelmChart{}, &HelmChartList{})
   227  }
   228  

View as plain text