1 // Copyright 2021 The Kubernetes Authors. 2 // SPDX-License-Identifier: Apache-2.0 3 4 package actuation 5 6 import ( 7 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 8 "k8s.io/apimachinery/pkg/types" 9 ) 10 11 // Inventory represents the inventory object in memory. 12 // Inventory is currently only used for in-memory storage and not serialized to 13 // disk or to the API server. 14 type Inventory struct { 15 metav1.TypeMeta `json:",inline"` 16 metav1.ObjectMeta `json:"metadata,omitempty"` 17 18 Spec InventorySpec `json:"spec,omitempty"` 19 Status InventoryStatus `json:"status,omitempty"` 20 } 21 22 // InventorySpec is the specification of the desired/expected inventory state. 23 type InventorySpec struct { 24 Objects []ObjectReference `json:"objects,omitempty"` 25 } 26 27 // InventoryStatus is the status of the current/last-known inventory state. 28 type InventoryStatus struct { 29 Objects []ObjectStatus `json:"objects,omitempty"` 30 } 31 32 // ObjectReference is a reference to a KRM resource by name and kind. 33 // 34 // Kubernetes only stores one API Version for each Kind at any given time, 35 // so version is not used when referencing objects. 36 type ObjectReference struct { 37 // Kind identifies a REST resource within a Group. 38 // More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds 39 Kind string `json:"kind,omitempty"` 40 41 // Group identifies an API namespace for REST resources. 42 // If group is omitted, it is treated as the "core" group. 43 // More info: https://kubernetes.io/docs/reference/using-api/#api-groups 44 // +optional 45 Group string `json:"group,omitempty"` 46 47 // Name identifies an object instance of a REST resource. 48 // More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names 49 Name string `json:"name,omitempty"` 50 51 // Namespace identifies a group of objects across REST resources. 52 // If namespace is specified, the resource must be namespace-scoped. 53 // If namespace is omitted, the resource must be cluster-scoped. 54 // More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/namespaces/ 55 // +optional 56 Namespace string `json:"namespace,omitempty"` 57 } 58 59 // ObjectStatus is a snapshot of the actuation and reconciliation status of a 60 // referenced object. 61 type ObjectStatus struct { 62 ObjectReference `json:",inline"` 63 64 // Strategy indicates the method of actuation (apply or delete) used or planned to be used. 65 Strategy ActuationStrategy `json:"strategy,omitempty"` 66 // Actuation indicates whether actuation has been performed yet and how it went. 67 Actuation ActuationStatus `json:"actuation,omitempty"` 68 // Reconcile indicates whether reconciliation has been performed yet and how it went. 69 Reconcile ReconcileStatus `json:"reconcile,omitempty"` 70 71 // UID is the last known UID (after apply or before delete). 72 // This can help identify if the object has been replaced. 73 // +optional 74 UID types.UID `json:"uid,omitempty"` 75 // Generation is the last known Generation (after apply or before delete). 76 // This can help identify if the object has been modified. 77 // Generation is not available for deleted objects. 78 // +optional 79 Generation int64 `json:"generation,omitempty"` 80 } 81 82 //nolint:revive // consistent prefix improves tab-completion for enums 83 //go:generate stringer -type=ActuationStrategy -linecomment 84 type ActuationStrategy int 85 86 const ( 87 ActuationStrategyApply ActuationStrategy = iota // Apply 88 ActuationStrategyDelete // Delete 89 ) 90 91 //nolint:revive // consistent prefix improves tab-completion for enums 92 //go:generate stringer -type=ActuationStatus -linecomment 93 type ActuationStatus int 94 95 const ( 96 ActuationPending ActuationStatus = iota // Pending 97 ActuationSucceeded // Succeeded 98 ActuationSkipped // Skipped 99 ActuationFailed // Failed 100 ) 101 102 //go:generate stringer -type=ReconcileStatus -linecomment 103 type ReconcileStatus int 104 105 const ( 106 ReconcilePending ReconcileStatus = iota // Pending 107 ReconcileSucceeded // Succeeded 108 ReconcileSkipped // Skipped 109 ReconcileFailed // Failed 110 ReconcileTimeout // Timeout 111 ) 112