github.com/juju/juju@v0.0.0-20240430160146-1752b71fcf00/caas/operator.go (about) 1 // Copyright 2019 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package caas 5 6 import ( 7 "github.com/juju/errors" 8 "gopkg.in/yaml.v2" 9 ) 10 11 const ( 12 // OperatorInfoFile is the file which contains certificate information for 13 // the operator. 14 OperatorInfoFile = "operator.yaml" 15 16 // OperatorClientInfoFile is the file containing info about the operator, 17 // copied to the workload pod so the hook tools and juju-exec can function. 18 OperatorClientInfoFile = "operator-client.yaml" 19 20 // OperatorClientInfoCacheFile is a cache of OperatorClientInfoFile stored on the operator. 21 OperatorClientInfoCacheFile = "operator-client-cache.yaml" 22 23 // CACertFile is the file containing the cluster CA. 24 CACertFile = "ca.crt" 25 26 // InitContainerName is the name of the init container on workloads pods. 27 InitContainerName = "juju-pod-init" 28 ) 29 30 // OperatorInfo contains information needed by CAAS operators 31 type OperatorInfo struct { 32 CACert string `yaml:"ca-cert,omitempty"` 33 Cert string `yaml:"cert,omitempty"` 34 PrivateKey string `yaml:"private-key,omitempty"` 35 } 36 37 // UnmarshalOperatorInfo parses OperatorInfo yaml data. 38 func UnmarshalOperatorInfo(data []byte) (*OperatorInfo, error) { 39 var oi OperatorInfo 40 err := yaml.Unmarshal(data, &oi) 41 if err != nil { 42 return nil, errors.Trace(err) 43 } 44 return &oi, nil 45 } 46 47 // Marshal OperatorInfo into yaml data. 48 func (info OperatorInfo) Marshal() ([]byte, error) { 49 return yaml.Marshal(info) 50 } 51 52 // OperatorClientInfo contains information needed by CAAS tools. 53 type OperatorClientInfo struct { 54 ServiceAddress string `yaml:"service-address,omitempty"` 55 Token string `yaml:"token,omitempty"` 56 } 57 58 // UnmarshalOperatorClientInfo parses OperatorClientInfo yaml data. 59 func UnmarshalOperatorClientInfo(data []byte) (*OperatorClientInfo, error) { 60 var oi OperatorClientInfo 61 err := yaml.Unmarshal(data, &oi) 62 if err != nil { 63 return nil, errors.Trace(err) 64 } 65 return &oi, nil 66 } 67 68 // Marshal OperatorClientInfo into yaml data. 69 func (info OperatorClientInfo) Marshal() ([]byte, error) { 70 return yaml.Marshal(info) 71 }