|
| 1 | +# Common |
| 2 | + |
| 3 | +Common defines resources used across all source types. |
| 4 | + |
| 5 | +## Specification |
| 6 | + |
| 7 | +### Source interface |
| 8 | + |
| 9 | +Source objects should adhere to the `Source` interface. This interface exposes the [interval](#source-synchronization) |
| 10 | +and [artifact](#source-status) of the source to clients without the prerequisite of knowing the source kind: |
| 11 | + |
| 12 | +````go |
| 13 | +type Source interface { |
| 14 | + // GetInterval returns the interval at which the source is updated. |
| 15 | + GetInterval() metav1.Duration |
| 16 | + |
| 17 | + // GetArtifact returns the latest artifact from the source, or nil. |
| 18 | + GetArtifact() *Artifact |
| 19 | +} |
| 20 | +```` |
| 21 | + |
| 22 | +### Source synchronization |
| 23 | + |
| 24 | +Source objects should contain a `spec.interval` field that tells the controller at which interval to check for updates: |
| 25 | + |
| 26 | +```go |
| 27 | +type SourceSpec struct { |
| 28 | + // The interval at which to check for source updates. |
| 29 | + // +required |
| 30 | + Interval metav1.Duration `json:"interval"` |
| 31 | +} |
| 32 | +``` |
| 33 | + |
| 34 | +Valid time units are `s`, `m` and `h` e.g. `interval: 5m`. |
| 35 | + |
| 36 | +The controller can be told to check for updates right away by setting an annotation on source objects: |
| 37 | + |
| 38 | +```go |
| 39 | +const ( |
| 40 | + // ForceSyncAnnotation is the timestamp corresponding to an on-demand source sync. |
| 41 | + ForceSyncAnnotation string = "source.fluxcd.io/syncAt" |
| 42 | +) |
| 43 | +``` |
| 44 | + |
| 45 | +Force sync example: |
| 46 | + |
| 47 | +```bash |
| 48 | +kubectl annotate --overwrite gitrepository/podinfo source.fluxcd.io/syncAt="$(date +%s)" |
| 49 | +``` |
| 50 | + |
| 51 | +### Source status |
| 52 | + |
| 53 | +Source objects should contain a status sub-resource that embeds an artifact object: |
| 54 | + |
| 55 | +```go |
| 56 | +// Artifact represents the output of a source synchronisation |
| 57 | +type Artifact struct { |
| 58 | + // Path is the local file path of this artifact. |
| 59 | + // +required |
| 60 | + Path string `json:"path"` |
| 61 | + |
| 62 | + // URL is the HTTP address of this artifact. |
| 63 | + // +required |
| 64 | + URL string `json:"url"` |
| 65 | + |
| 66 | + // Revision is a human readable identifier traceable in the origin source system. |
| 67 | + // It can be a commit sha, git tag, a helm index timestamp, |
| 68 | + // a helm chart version, a checksum, etc. |
| 69 | + // +optional |
| 70 | + Revision string `json:"revision"` |
| 71 | + |
| 72 | + // LastUpdateTime is the timestamp corresponding to the last |
| 73 | + // update of this artifact. |
| 74 | + // +required |
| 75 | + LastUpdateTime metav1.Time `json:"lastUpdateTime,omitempty"` |
| 76 | +} |
| 77 | +``` |
| 78 | + |
| 79 | +### Source condition |
| 80 | + |
| 81 | +> **Note:** to be replaced with <https://github.com/kubernetes/enhancements/pull/1624> |
| 82 | +> once made available. |
| 83 | +
|
| 84 | +```go |
| 85 | +// SourceCondition contains condition information for a source. |
| 86 | +type SourceCondition struct { |
| 87 | + // Type of the condition, currently ('Ready'). |
| 88 | + // +required |
| 89 | + Type string `json:"type"` |
| 90 | + |
| 91 | + // Status of the condition, one of ('True', 'False', 'Unknown'). |
| 92 | + // +required |
| 93 | + Status corev1.ConditionStatus `json:"status"` |
| 94 | + |
| 95 | + // LastTransitionTime is the timestamp corresponding to the last status |
| 96 | + // change of this condition. |
| 97 | + // +required |
| 98 | + LastTransitionTime metav1.Time `json:"lastTransitionTime,omitempty"` |
| 99 | + |
| 100 | + // Reason is a brief machine readable explanation for the condition's last |
| 101 | + // transition. |
| 102 | + // +required |
| 103 | + Reason string `json:"reason,omitempty"` |
| 104 | + |
| 105 | + // Message is a human readable description of the details of the last |
| 106 | + // transition, complementing reason. |
| 107 | + // +optional |
| 108 | + Message string `json:"message,omitempty"` |
| 109 | +} |
| 110 | +``` |
| 111 | + |
| 112 | +#### Types |
| 113 | + |
| 114 | +```go |
| 115 | +const ( |
| 116 | + // ReadyCondition represents the fact that a given source is in ready state. |
| 117 | + ReadyCondition string = "Ready" |
| 118 | +) |
| 119 | +``` |
| 120 | + |
| 121 | +#### Reasons |
| 122 | + |
| 123 | +```go |
| 124 | +const ( |
| 125 | + // InitializingReason represents the fact that a given source is being initialized. |
| 126 | + InitializingReason string = "Initializing" |
| 127 | + |
| 128 | + // URLInvalidReason represents the fact that a given source has an invalid URL. |
| 129 | + URLInvalidReason string = "URLInvalid" |
| 130 | + |
| 131 | + // StorageOperationFailedReason signals a failure caused by a storage operation. |
| 132 | + StorageOperationFailedReason string = "StorageOperationFailed" |
| 133 | + |
| 134 | + // AuthenticationFailedReason represents the fact that a given secret does not |
| 135 | + // have the required fields or the provided credentials do not match. |
| 136 | + AuthenticationFailedReason string = "AuthenticationFailed" |
| 137 | + |
| 138 | + // VerificationFailedReason represents the fact that the cryptographic provenance |
| 139 | + // verification for the source failed. |
| 140 | + VerificationFailedReason string = "VerificationFailed" |
| 141 | +) |
| 142 | +``` |
| 143 | + |
| 144 | +## Examples |
| 145 | + |
| 146 | +See the [Git repository](gitrepositories.md) and [Helm chart](helmrepositories.md) APIs. |
0 commit comments