|
| 1 | +package v1alpha1 |
| 2 | + |
| 3 | +import metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" |
| 4 | + |
| 5 | +// +genclient |
| 6 | +// +genclient:nonNamespaced |
| 7 | +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object |
| 8 | + |
| 9 | +// CRIOCredentialProviderConfig holds cluster-wide configurations for CRI-O credential provider. CRI-O credential provider is a binary shipped with CRI-O that provides a way to obtain container image pull credentials from external sources. |
| 10 | +// For example, it can be used to fetch mirror registry credentials from secrets resources in the cluster within the same namespace the pod will be running in. |
| 11 | +// CRIOCredentialProviderConfig configuration specifies the pod image sources registries that should trigger the CRI-O credential provider execution, which will resolve the CRI-O mirror configurations and obtain the necessary credentials for pod creation. |
| 12 | +// |
| 13 | +// Compatibility level 4: No compatibility is provided, the API can change at any point for any reason. These capabilities should not be used by applications needing long term support. |
| 14 | +// +kubebuilder:object:root=true |
| 15 | +// +kubebuilder:resource:path=criocredentialproviderconfigs,scope=Cluster |
| 16 | +// +kubebuilder:subresource:status |
| 17 | +// +openshift:api-approved.openshift.io=https://github.com/openshift/api/pull/1929 |
| 18 | +// +openshift:file-pattern=cvoRunLevel=0000_10,operatorName=config-operator,operatorOrdering=01 |
| 19 | +// +openshift:enable:FeatureGate=CRIOCredentialProviderConfig |
| 20 | +// +openshift:compatibility-gen:level=4 |
| 21 | +type CRIOCredentialProviderConfig struct { |
| 22 | + metav1.TypeMeta `json:",inline"` |
| 23 | + |
| 24 | + // metadata is the standard object's metadata. |
| 25 | + // More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata |
| 26 | + metav1.ObjectMeta `json:"metadata,omitempty"` |
| 27 | + |
| 28 | + // Spec defines the desired configuration of the CRIO Credential Provider. |
| 29 | + // +required |
| 30 | + Spec CRIOCredentialProviderConfigSpec `json:"spec,omitempty"` |
| 31 | + |
| 32 | + // Status represents the current state of the CRIOCredentialProviderConfig. |
| 33 | + // +optional |
| 34 | + Status CRIOCredentialProviderConfigStatus `json:"status,omitempty"` |
| 35 | +} |
| 36 | + |
| 37 | +// CRIOCredentialProviderConfigSpec defines the desired configuration of the CRI-O Credential Provider. |
| 38 | +type CRIOCredentialProviderConfigSpec struct { |
| 39 | + // matchImages is a required list of string patterns used to determine whether |
| 40 | + // the CRI-O credential provider should be invoked for a given image. This list is |
| 41 | + // passed to the kubelet CredentialProviderConfig, and if any pattern matches |
| 42 | + // the requested image, CRI-O credential provider will be invoked to obtain credentials for pulling |
| 43 | + // that image or its mirrors. |
| 44 | + // |
| 45 | + // For more details, see: |
| 46 | + // - https://kubernetes.io/docs/tasks/administer-cluster/kubelet-credential-provider/ |
| 47 | + // - https://github.com/cri-o/crio-credential-provider#architecture |
| 48 | + // |
| 49 | + // Each entry in matchImages is a pattern which can optionally contain a port and a path. |
| 50 | + // Wildcards ('*') are supported for full subdomain labels, such as '*.k8s.io' or 'k8s.*.io', |
| 51 | + // and for top-level domains, such as 'k8s.*' (which matches 'k8s.io' or 'k8s.net'). |
| 52 | + // Wildcards are not allowed in the port or path, nor may they appear in the middle of a hostname label. |
| 53 | + // For example, '*.example.com' is valid, but 'example*.*.com' is not. |
| 54 | + // Each wildcard matches only a single domain label, |
| 55 | + // so '*.io' does **not** match '*.k8s.io'. |
| 56 | + // |
| 57 | + // A match exists between an image and a matchImage when all of the below are true: |
| 58 | + // - Both contain the same number of domain parts and each part matches. |
| 59 | + // - The URL path of an matchImages must be a prefix of the target image URL path. |
| 60 | + // - If the matchImages contains a port, then the port must match in the image as well. |
| 61 | + // |
| 62 | + // Example values of matchImages: |
| 63 | + // - 123456789.dkr.ecr.us-east-1.amazonaws.com |
| 64 | + // - *.azurecr.io |
| 65 | + // - gcr.io |
| 66 | + // - *.*.registry.io |
| 67 | + // - registry.io:8080/path |
| 68 | + // |
| 69 | + // +kubebuilder:validation:MaxItems=50 |
| 70 | + // +listType=set |
| 71 | + // +kubebuilder:validation:Required |
| 72 | + MatchImages []MatchImage `json:"matchImages"` |
| 73 | +} |
| 74 | + |
| 75 | +// +kubebuilder:validation:MaxLength=512 |
| 76 | +// +kubebuilder:validation:XValidation:rule=`self.matches('^((\*|[a-zA-Z0-9]([a-zA-Z0-9-]*[a-zA-Z0-9])?)(\.(\*|[a-zA-Z0-9]([a-zA-Z0-9-]*[a-zA-Z0-9])?))*)(:[0-9]+)?(/[-a-zA-Z0-9_/]*)?$')`,message="invalid matchImages value, must be a valid fully qualified domain name with optional wildcard, port, and path" |
| 77 | +type MatchImage string |
| 78 | + |
| 79 | +// +k8s:deepcopy-gen=true |
| 80 | +// CRIOCredentialProviderConfigStatus defines the observed state of CRIOCredentialProviderConfig |
| 81 | +type CRIOCredentialProviderConfigStatus struct { |
| 82 | + // Conditions represent the latest available observations of the configuration state |
| 83 | + // +optional |
| 84 | + // +listType=map |
| 85 | + // +listMapKey=type |
| 86 | + Conditions []metav1.Condition `json:"conditions,omitempty"` |
| 87 | +} |
| 88 | + |
| 89 | +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object |
| 90 | + |
| 91 | +// CRIOCredentialProviderConfigList contains a list of CRIOCredentialProviderConfig resources |
| 92 | +// |
| 93 | +// Compatibility level 4: No compatibility is provided, the API can change at any point for any reason. These capabilities should not be used by applications needing long term support. |
| 94 | +// +openshift:compatibility-gen:level=4 |
| 95 | +type CRIOCredentialProviderConfigList struct { |
| 96 | + metav1.TypeMeta `json:",inline"` |
| 97 | + |
| 98 | + // metadata is the standard list's metadata. |
| 99 | + // More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata |
| 100 | + metav1.ListMeta `json:"metadata"` |
| 101 | + |
| 102 | + Items []CRIOCredentialProviderConfig `json:"items"` |
| 103 | +} |
| 104 | + |
| 105 | +const ( |
| 106 | + // ConditionTypeValidated indicates whether the configuration is failed, or partially valid |
| 107 | + ConditionTypeValidated = "Validated" |
| 108 | + |
| 109 | + // ReasonValidationFailed indicates the MatchImages configuration contains invalid patterns |
| 110 | + ReasonValidationFailed = "ValidationFailed" |
| 111 | + |
| 112 | + // ReasonConfigurationPartiallyApplied indicates some matchImage entries were ignored due to conflicts |
| 113 | + ReasonConfigurationPartiallyApplied = "ConfigurationPartiallyApplied" |
| 114 | +) |
0 commit comments