Skip to content

Commit 4ddf13f

Browse files
committed
Add OCIRepository kind to v1beta2 API
Signed-off-by: Stefan Prodan <stefan.prodan@gmail.com>
1 parent 812f6e4 commit 4ddf13f

9 files changed

+1325
-1
lines changed

PROJECT

+3
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,7 @@ resources:
2525
- group: source
2626
kind: Bucket
2727
version: v1beta1
28+
- group: source
29+
kind: OCIRepository
30+
version: v1beta2
2831
version: "2"

api/v1beta2/ocirepository_types.go

+204
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,204 @@
1+
/*
2+
Copyright 2022 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 v1beta2
18+
19+
import (
20+
"github.com/fluxcd/pkg/apis/meta"
21+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
22+
"time"
23+
)
24+
25+
const (
26+
// OCIRepositoryKind is the string representation of a OCIRepository.
27+
OCIRepositoryKind = "OCIRepository"
28+
)
29+
30+
// OCIRepositorySpec defines the desired state of OCIRepository
31+
type OCIRepositorySpec struct {
32+
// URL is a reference to an OCI artifact repository hosted
33+
// on a remote container registry.
34+
// +required
35+
URL string `json:"url"`
36+
37+
// The OCI reference to pull and monitor for changes,
38+
// defaults to the latest tag.
39+
// +optional
40+
Reference *OCIRepositoryRef `json:"ref,omitempty"`
41+
42+
// SecretRef contains the secret name containing the registry login
43+
// credentials to resolve image metadata.
44+
// The secret must be of type kubernetes.io/dockerconfigjson.
45+
// +optional
46+
SecretRef *meta.LocalObjectReference `json:"secretRef,omitempty"`
47+
48+
// ServiceAccountName is the name of the Kubernetes ServiceAccount used to authenticate
49+
// the image pull if the service account has attached pull secrets. For more information:
50+
// https://kubernetes.io/docs/tasks/configure-pod-container/configure-service-account/#add-imagepullsecrets-to-a-service-account
51+
// +optional
52+
ServiceAccountName string `json:"serviceAccountName,omitempty"`
53+
54+
// CertSecretRef can be given the name of a secret containing
55+
// either or both of
56+
//
57+
// - a PEM-encoded client certificate (`certFile`) and private
58+
// key (`keyFile`);
59+
// - a PEM-encoded CA certificate (`caFile`)
60+
//
61+
// and whichever are supplied, will be used for connecting to the
62+
// registry. The client cert and key are useful if you are
63+
// authenticating with a certificate; the CA cert is useful if
64+
// you are using a self-signed server certificate.
65+
// +optional
66+
CertSecretRef *meta.LocalObjectReference `json:"certSecretRef,omitempty"`
67+
68+
// Verification specifies the configuration to verify the autheticity
69+
// of an OCI Artifact.
70+
// +optional
71+
Verification *OCIRepositoryVerification `json:"verify,omitempty"`
72+
73+
// The interval at which to check for image updates.
74+
// +required
75+
Interval metav1.Duration `json:"interval"`
76+
77+
// The timeout for remote OCI Repository operations like pulling, defaults to 60s.
78+
// +kubebuilder:default="60s"
79+
// +optional
80+
Timeout *metav1.Duration `json:"timeout,omitempty"`
81+
82+
// Ignore overrides the set of excluded patterns in the .sourceignore format
83+
// (which is the same as .gitignore). If not provided, a default will be used,
84+
// consult the documentation for your version to find out what those are.
85+
// +optional
86+
Ignore *string `json:"ignore,omitempty"`
87+
88+
// This flag tells the controller to suspend the reconciliation of this source.
89+
// +optional
90+
Suspend bool `json:"suspend,omitempty"`
91+
}
92+
93+
// OCIRepositoryRef defines the image reference for the OCIRepository's URL
94+
type OCIRepositoryRef struct {
95+
// Digest is the image digest to pull, takes precedence over SemVer.
96+
// The value should be in the format 'sha256:<HASH>'.
97+
// +optional
98+
Digest string `json:"digest,omitempty"`
99+
100+
// SemVer is the range of tags to pull selecting the latest within
101+
// the range, takes precedence over Tag.
102+
// +optional
103+
SemVer string `json:"semver,omitempty"`
104+
105+
// Tag is the image tag to pull, defaults to latest.
106+
// +kubebuilder:default:=latest
107+
// +optional
108+
Tag string `json:"tag,omitempty"`
109+
}
110+
111+
// OCIRepositoryVerification verifies the authenticity of an OCI Artifact
112+
type OCIRepositoryVerification struct {
113+
// Provider specifies the technology used to sign the OCI Artifact.
114+
// +kubebuilder:validation:Enum=cosign
115+
Provider string `json:"provider"`
116+
117+
// SecretRef specifies the Kubernetes Secret containing the
118+
// trusted public keys.
119+
SecretRef meta.LocalObjectReference `json:"secretRef"`
120+
}
121+
122+
// OCIRepositoryStatus defines the observed state of OCIRepository
123+
type OCIRepositoryStatus struct {
124+
// ObservedGeneration is the last observed generation.
125+
// +optional
126+
ObservedGeneration int64 `json:"observedGeneration,omitempty"`
127+
128+
// Conditions holds the conditions for the OCIRepository.
129+
// +optional
130+
Conditions []metav1.Condition `json:"conditions,omitempty"`
131+
132+
// URL is the download link for the artifact output of the last OCI Repository sync.
133+
// +optional
134+
URL string `json:"url,omitempty"`
135+
136+
// Artifact represents the output of the last successful OCI Repository sync.
137+
// +optional
138+
Artifact *Artifact `json:"artifact,omitempty"`
139+
140+
meta.ReconcileRequestStatus `json:",inline"`
141+
}
142+
143+
const (
144+
// OCIOperationSucceedReason signals that a Git operation (e.g. pull) succeeded.
145+
OCIOperationSucceedReason string = "OCIOperationSucceeded"
146+
147+
// OCIOperationFailedReason signals that an OCI operation (e.g. pull) failed.
148+
OCIOperationFailedReason string = "OCIOperationFailed"
149+
)
150+
151+
// GetConditions returns the status conditions of the object.
152+
func (in OCIRepository) GetConditions() []metav1.Condition {
153+
return in.Status.Conditions
154+
}
155+
156+
// SetConditions sets the status conditions on the object.
157+
func (in *OCIRepository) SetConditions(conditions []metav1.Condition) {
158+
in.Status.Conditions = conditions
159+
}
160+
161+
// GetRequeueAfter returns the duration after which the GitRepository must be
162+
// reconciled again.
163+
func (in OCIRepository) GetRequeueAfter() time.Duration {
164+
return in.Spec.Interval.Duration
165+
}
166+
167+
// GetArtifact returns the latest Artifact from the GitRepository if present in
168+
// the status sub-resource.
169+
func (in *OCIRepository) GetArtifact() *Artifact {
170+
return in.Status.Artifact
171+
}
172+
173+
// +genclient
174+
// +genclient:Namespaced
175+
// +kubebuilder:storageversion
176+
// +kubebuilder:object:root=true
177+
// +kubebuilder:resource:shortName=ocirepo
178+
// +kubebuilder:subresource:status
179+
// +kubebuilder:printcolumn:name="URL",type=string,JSONPath=`.spec.url`
180+
// +kubebuilder:printcolumn:name="Ready",type="string",JSONPath=".status.conditions[?(@.type==\"Ready\")].status",description=""
181+
// +kubebuilder:printcolumn:name="Status",type="string",JSONPath=".status.conditions[?(@.type==\"Ready\")].message",description=""
182+
// +kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp",description=""
183+
184+
// OCIRepository is the Schema for the ocirepositories API
185+
type OCIRepository struct {
186+
metav1.TypeMeta `json:",inline"`
187+
metav1.ObjectMeta `json:"metadata,omitempty"`
188+
189+
Spec OCIRepositorySpec `json:"spec,omitempty"`
190+
// +kubebuilder:default={"observedGeneration":-1}
191+
Status OCIRepositoryStatus `json:"status,omitempty"`
192+
}
193+
194+
// OCIRepositoryList contains a list of OCIRepository
195+
// +kubebuilder:object:root=true
196+
type OCIRepositoryList struct {
197+
metav1.TypeMeta `json:",inline"`
198+
metav1.ListMeta `json:"metadata,omitempty"`
199+
Items []OCIRepository `json:"items"`
200+
}
201+
202+
func init() {
203+
SchemeBuilder.Register(&OCIRepository{}, &OCIRepositoryList{})
204+
}

api/v1beta2/zz_generated.deepcopy.go

+164
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)