github.com/juju/juju@v0.0.0-20240430160146-1752b71fcf00/rpc/params/caas.go (about) 1 // Copyright 2020 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package params 5 6 import ( 7 "github.com/juju/names/v5" 8 "github.com/juju/version/v2" 9 10 "github.com/juju/juju/core/constraints" 11 "github.com/juju/juju/core/resources" 12 "github.com/juju/juju/docker" 13 ) 14 15 // CAASUnitIntroductionArgs is used by sidecar units to introduce 16 // themselves via CAASApplication facade. 17 type CAASUnitIntroductionArgs struct { 18 PodName string `json:"pod-name"` 19 PodUUID string `json:"pod-uuid"` 20 } 21 22 // CAASUnitIntroduction contains the agent config for CAASApplication units. 23 type CAASUnitIntroduction struct { 24 UnitName string `json:"unit-name"` 25 AgentConf []byte `json:"agent-conf"` 26 } 27 28 // CAASUnitIntroductionResult is returned from CAASApplication facade. 29 type CAASUnitIntroductionResult struct { 30 Result *CAASUnitIntroduction `json:"result,omitempty"` 31 Error *Error `json:"error,omitempty"` 32 } 33 34 // CAASApplicationProvisioningInfoResults holds OperatorProvisioningInfo results. 35 type CAASApplicationProvisioningInfoResults struct { 36 Results []CAASApplicationProvisioningInfo `json:"results"` 37 } 38 39 // CAASUnitTerminationResult holds result to UnitTerminating call. 40 type CAASUnitTerminationResult struct { 41 // WillRestart is true if the termination of the unit is temporary. 42 WillRestart bool 43 Error *Error 44 } 45 46 // CAASApplicationProvisioningInfo holds info needed to provision a caas application. 47 type CAASApplicationProvisioningInfo struct { 48 Version version.Number `json:"version"` 49 APIAddresses []string `json:"api-addresses"` 50 CACert string `json:"ca-cert"` 51 Constraints constraints.Value `json:"constraints"` 52 Tags map[string]string `json:"tags,omitempty"` 53 Filesystems []KubernetesFilesystemParams `json:"filesystems,omitempty"` 54 Volumes []KubernetesVolumeParams `json:"volumes,omitempty"` 55 Devices []KubernetesDeviceParams `json:"devices,omitempty"` 56 Base Base `json:"base,omitempty"` 57 ImageRepo DockerImageInfo `json:"image-repo,omitempty"` 58 CharmModifiedVersion int `json:"charm-modified-version,omitempty"` 59 CharmURL string `json:"charm-url,omitempty"` 60 Trust bool `json:"trust,omitempty"` 61 Scale int `json:"scale,omitempty"` 62 Error *Error `json:"error,omitempty"` 63 } 64 65 // DockerImageInfo holds the details for a Docker resource type. 66 type DockerImageInfo struct { 67 // RegistryPath holds the path of the Docker image (including host and sha256) in a docker registry. 68 RegistryPath string `json:"image-name"` 69 70 // Username holds the username used to gain access to a non-public image. 71 Username string `json:"username,omitempty"` 72 73 // Password holds the password used to gain access to a non-public image. 74 Password string `json:"password,omitempty"` 75 76 // Auth is the base64 encoded "username:password" string. 77 Auth string `json:"auth,omitempty" yaml:"auth,omitempty"` 78 79 // IdentityToken is used to authenticate the user and get 80 // an access token for the registry. 81 IdentityToken string `json:"identitytoken,omitempty" yaml:"identitytoken,omitempty"` 82 83 // RegistryToken is a bearer token to be sent to a registry 84 RegistryToken string `json:"registrytoken,omitempty" yaml:"registrytoken,omitempty"` 85 86 Email string `json:"email,omitempty" yaml:"email,omitempty"` 87 88 // ServerAddress is the auth server address. 89 ServerAddress string `json:"serveraddress,omitempty" yaml:"serveraddress,omitempty"` 90 91 // Repository is the namespace of the image repo. 92 Repository string `json:"repository,omitempty" yaml:"repository,omitempty"` 93 } 94 95 // NewDockerImageInfo converts docker.ImageRepoDetails to DockerImageInfo. 96 func NewDockerImageInfo(info docker.ImageRepoDetails, registryPath string) DockerImageInfo { 97 return DockerImageInfo{ 98 Username: info.Username, 99 Password: info.Password, 100 Email: info.Email, 101 Repository: info.Repository, 102 Auth: info.Auth.Content(), 103 IdentityToken: info.IdentityToken.Content(), 104 RegistryToken: info.RegistryToken.Content(), 105 RegistryPath: registryPath, 106 } 107 } 108 109 // ConvertDockerImageInfo converts DockerImageInfo to resources.ImageRepoDetails. 110 func ConvertDockerImageInfo(info DockerImageInfo) resources.DockerImageDetails { 111 return resources.DockerImageDetails{ 112 RegistryPath: info.RegistryPath, 113 ImageRepoDetails: docker.ImageRepoDetails{ 114 Repository: info.Repository, 115 ServerAddress: info.ServerAddress, 116 BasicAuthConfig: docker.BasicAuthConfig{ 117 Username: info.Username, 118 Password: info.Password, 119 Auth: docker.NewToken(info.Auth), 120 }, 121 TokenAuthConfig: docker.TokenAuthConfig{ 122 IdentityToken: docker.NewToken(info.IdentityToken), 123 RegistryToken: docker.NewToken(info.RegistryToken), 124 Email: info.Email, 125 }, 126 }, 127 } 128 } 129 130 // CAASApplicationOCIResourceResults holds all the image results for queried applications. 131 type CAASApplicationOCIResourceResults struct { 132 Results []CAASApplicationOCIResourceResult `json:"results"` 133 } 134 135 // CAASApplicationOCIResourceResult holds the image result or error for the queried application. 136 type CAASApplicationOCIResourceResult struct { 137 Result *CAASApplicationOCIResources `json:"result,omitempty"` 138 Error *Error `json:"error,omitempty"` 139 } 140 141 // CAASApplicationOCIResources holds a list of image OCI resources. 142 type CAASApplicationOCIResources struct { 143 Images map[string]DockerImageInfo `json:"images"` 144 } 145 146 // CAASUnitInfo holds CAAS unit information. 147 type CAASUnitInfo struct { 148 Tag string `json:"tag"` 149 UnitStatus *UnitStatus `json:"unit-status,omitempty"` 150 } 151 152 // CAASUnit holds CAAS unit information. 153 type CAASUnit struct { 154 Tag names.Tag 155 UnitStatus *UnitStatus 156 } 157 158 // CAASUnitsResult holds a slice of CAAS unit information or an error. 159 type CAASUnitsResult struct { 160 Units []CAASUnitInfo `json:"units,omitempty"` 161 Error *Error `json:"error,omitempty"` 162 } 163 164 // CAASUnitsResults contains multiple CAAS units result. 165 type CAASUnitsResults struct { 166 Results []CAASUnitsResult `json:"results"` 167 } 168 169 // CAASApplicationProvisioningState represents the provisioning state for a CAAS application. 170 type CAASApplicationProvisioningState struct { 171 Scaling bool `json:"scaling"` 172 ScaleTarget int `json:"scale-target"` 173 } 174 175 // CAASApplicationProvisioningStateResult represents the result of getting the 176 // provisioning state for a CAAS application. 177 type CAASApplicationProvisioningStateResult struct { 178 ProvisioningState *CAASApplicationProvisioningState `json:"provisioning-state,omitempty"` 179 Error *Error `json:"error,omitempty"` 180 } 181 182 // CAASApplicationProvisioningStateArg holds the arguments for setting a CAAS application's 183 // provisioning state. 184 type CAASApplicationProvisioningStateArg struct { 185 Application Entity `json:"application"` 186 ProvisioningState CAASApplicationProvisioningState `json:"provisioning-state"` 187 } 188 189 // CAASApplicationProvisionerConfig holds the configuration for the caasapplicationprovisioner worker. 190 type CAASApplicationProvisionerConfig struct { 191 UnmanagedApplications Entities `json:"unmanaged-applications,omitempty"` 192 } 193 194 // CAASApplicationProvisionerConfigResult is the result of getting the caasapplicationprovisioner worker's 195 // configuration for the current model. 196 type CAASApplicationProvisionerConfigResult struct { 197 ProvisionerConfig *CAASApplicationProvisionerConfig `json:"provisioner-config,omitempty"` 198 Error *Error `json:"error,omitempty"` 199 }