github.com/crossplane/upjet@v1.3.0/pkg/migration/types.go (about) 1 // SPDX-FileCopyrightText: 2023 The Crossplane Authors <https://crossplane.io> 2 // 3 // SPDX-License-Identifier: Apache-2.0 4 5 package migration 6 7 import ( 8 "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" 9 ) 10 11 // FinalizerPolicy denotes the policy regarding the managed reconciler's 12 // finalizer while deleting a managed resource. 13 type FinalizerPolicy string 14 15 const ( 16 // FinalizerPolicyRemove is the FinalizerPolicy for removing 17 // the managed reconciler's finalizer from a managed resource. 18 FinalizerPolicyRemove FinalizerPolicy = "Remove" // Default 19 ) 20 21 // Resource categories 22 const ( 23 categoryUnknown Category = "" 24 // CategoryClaim category for composite claim resources 25 CategoryClaim Category = "claim" 26 // CategoryComposite category for composite resources 27 CategoryComposite Category = "composite" 28 // CategoryComposition category for compositions 29 CategoryComposition Category = "composition" 30 // CategoryManaged category for managed resources 31 CategoryManaged Category = "managed" 32 // CategoryCrossplanePackage category for provider packages 33 CategoryCrossplanePackage Category = "package" 34 ) 35 36 // Plan represents a migration plan for migrating managed resources, 37 // and associated composites and claims from a migration source provider 38 // to a migration target provider. 39 type Plan struct { 40 Version string `json:"version"` 41 Spec Spec `json:"spec,omitempty"` 42 } 43 44 // Spec represents the specification of a migration plan 45 type Spec struct { 46 // Steps are the migration plan's steps that are expected 47 // to complete a migration when executed in order. 48 Steps []Step `json:"steps,omitempty"` 49 stepMap map[string]*Step 50 } 51 52 // StepType is the type used to name a migration step 53 type StepType string 54 55 const ( 56 // StepTypeApply denotes an apply step 57 StepTypeApply StepType = "Apply" 58 // StepTypePatch denotes a patch step, where a resource is patched 59 // using the given JSON patch document. 60 StepTypePatch StepType = "Patch" 61 // StepTypeDelete denotes a delete step 62 StepTypeDelete StepType = "Delete" 63 // StepTypeExec executes the command with provided args 64 StepTypeExec StepType = "Exec" 65 ) 66 67 // Step represents a step in the generated migration plan 68 type Step struct { 69 // Name is the name of this Step 70 Name string `json:"name"` 71 // Type is the type of this Step. 72 // Can be one of Apply, Delete, etc. 73 Type StepType `json:"type"` 74 // Apply contains the information needed to run an StepTypeApply step. 75 // Must be set when the Step.Type is StepTypeApply. 76 Apply *ApplyStep `json:"apply,omitempty" yaml:"apply,omitempty"` 77 // Patch contains the information needed to run a StepTypePatch step. 78 Patch *PatchStep `json:"patch,omitempty" yaml:"patch,omitempty"` 79 // Delete contains the information needed to run an StepTypeDelete step. 80 // Must be set when the Step.Type is StepTypeDelete. 81 Delete *DeleteStep `json:"delete,omitempty" yaml:"delete,omitempty"` 82 // Exec contains the information needed to run a StepTypeExec step. 83 Exec *ExecStep `json:"exec,omitempty" yaml:"exec,omitempty"` 84 // ManualExecution string is to make copy/pasting easier for folks. 85 ManualExecution []string `json:"manualExecution,omitempty" yaml:"manualExecution,omitempty"` 86 } 87 88 // ApplyStep represents an apply step in which an array of manifests 89 // is applied from the filesystem. 90 type ApplyStep struct { 91 // Files denotes the paths of the manifest files to be applied. 92 // The paths can either be relative or absolute. 93 Files []string `json:"files,omitempty"` 94 } 95 96 // PatchType represents the patch type used in a patch operation 97 type PatchType string 98 99 const ( 100 // PatchTypeStrategic represents the strategic merge patch 101 PatchTypeStrategic PatchType = "strategic" 102 // PatchTypeMerge represents the RFC 7386 JSON merge patch 103 PatchTypeMerge PatchType = "merge" 104 // PatchTypeJSON represents the RFC 6902 JSON patch 105 PatchTypeJSON PatchType = "json" 106 ) 107 108 // PatchStep represents a patch step in which an array of manifests 109 // is used to patch resources. 110 type PatchStep struct { 111 // Files denotes the paths of the manifest files 112 // to be used as patch documents. 113 // The paths can either be relative or absolute. 114 Files []string `json:"files,omitempty"` 115 // Type is the PatchType to be used in this step 116 Type PatchType `json:"type,omitempty"` 117 } 118 119 // DeleteStep represents a deletion step with options 120 type DeleteStep struct { 121 // Options represents the options to be used while deleting the resources 122 // specified in Resources. 123 Options *DeleteOptions `json:"options,omitempty"` 124 // Resources is the array of resources to be deleted in this step 125 Resources []Resource `json:"resources,omitempty"` 126 } 127 128 // DeleteOptions represent options to be used during deletion of 129 // a managed resource. 130 type DeleteOptions struct { 131 // FinalizerPolicy denotes the policy to be used regarding 132 // the managed reconciler's finalizer 133 FinalizerPolicy *FinalizerPolicy `json:"finalizerPolicy,omitempty"` 134 } 135 136 // ExecStep represents an exec command with its arguments 137 type ExecStep struct { 138 // Command is the command to run 139 Command string `json:"command"` 140 // Args is the arguments of the command 141 Args []string `json:"args"` 142 } 143 144 // GroupVersionKind represents the GVK for an object's kind. 145 // schema.GroupVersionKind does not contain json the serialization tags 146 // for its fields, but we would like to serialize these as part of the 147 // migration plan. 148 type GroupVersionKind struct { 149 // Group is the API group for the resource 150 Group string `json:"group"` 151 // Version is the API version for the resource 152 Version string `json:"version"` 153 // Kind is the kind name for the resource 154 Kind string `json:"kind"` 155 } 156 157 type Resource struct { 158 // GroupVersionKind holds the GVK for the resource's type 159 // schema.GroupVersionKind is not embedded for consistent serialized names 160 GroupVersionKind `json:",inline"` 161 // Name is the name of the resource 162 Name string `json:"name"` 163 } 164 165 // Category specifies if a resource is a Claim, Composite or a Managed resource 166 type Category string 167 168 // String returns a string representing the receiver Category. 169 func (c Category) String() string { 170 return string(c) 171 } 172 173 // Metadata holds metadata for an object read from a Source 174 type Metadata struct { 175 // Path uniquely identifies the path for this object on its Source 176 Path string 177 // colon separated list of parent `Path`s for fan-ins and fan-outs 178 // Example: resources/a.yaml:resources/b.yaml 179 Parents string 180 // Category specifies if the associated resource is a Claim, Composite or a 181 // Managed resource 182 Category Category 183 } 184 185 // UnstructuredWithMetadata represents an unstructured.Unstructured 186 // together with the associated Metadata. 187 type UnstructuredWithMetadata struct { 188 Object unstructured.Unstructured 189 Metadata Metadata 190 }