github.com/Equinix-Metal/virtlet@v1.5.2-0.20210807010419-342346535dc5/pkg/api/virtlet.k8s/v1/imagemapping.go (about) 1 /* 2 Copyright 2018 Mirantis 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or ≈git-agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package v1 18 19 import ( 20 meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1" 21 ) 22 23 // TranslationRule represents a single translation rule from either name or regexp to Endpoint 24 type TranslationRule struct { 25 // Name defines a mapping from a fixed name 26 Name string `yaml:"name,omitempty" json:"name,omitempty"` 27 28 // Regex defines a mapping from all names that match this regexp. In this case replacements can be used for Endpoint.URL 29 Regex string `yaml:"regexp,omitempty" json:"regexp,omitempty"` 30 31 // URL is the image URL 32 URL string `yaml:"url,omitempty" json:"url,omitempty"` 33 34 // Transport is the optional transport profile name to be used for the downloading 35 Transport string `yaml:"transport,omitempty" json:"transport,omitempty"` 36 } 37 38 // ImageTranslation is a single translation config with optional prefix name 39 type ImageTranslation struct { 40 // Prefix allows to have several config-sets and distinguish them by using `prefix/imageName` notation. Optional. 41 Prefix string `yaml:"prefix,omitempty" json:"prefix,omitempty"` 42 43 // Rules is a list of translations 44 Rules []TranslationRule `yaml:"translations" json:"translations"` 45 46 // Transports is a map of available transport profiles available for endpoints 47 Transports map[string]TransportProfile `yaml:"transports" json:"transports"` 48 } 49 50 // TransportProfile contains all the http transport settings 51 type TransportProfile struct { 52 // MaxRedirects is the maximum number of redirects that downloader is allowed to follow. Default is 9 (download fails on request #10) 53 MaxRedirects *int `yaml:"maxRedirects,omitempty" json:"maxRedirects,omitempty"` 54 55 // TLS config 56 TLS *TLSConfig `yaml:"tls,omitempty" json:"tls,omitempty"` 57 58 // TimeoutMilliseconds specifies a time limit in milliseconds for http(s) download request. <= 0 is no timeout (default) 59 TimeoutMilliseconds int `yaml:"timeout,omitempty" json:"timeout,omitempty"` 60 61 // Proxy server to use for downloading 62 Proxy string `yaml:"proxy,omitempty" json:"proxy,omitempty"` 63 } 64 65 // TLSConfig has the TLS transport parameters 66 type TLSConfig struct { 67 // Certificates - TLS certificates to use for connection 68 Certificates []TLSCertificate `yaml:"certificates,omitempty" json:"certificates,omitempty"` 69 70 // ServerName is used to verify the hostname on the returned certificates. Needed when url points to domain that 71 // differs from CN of certificate 72 ServerName string `yaml:"serverName,omitempty" json:"serverName,omitempty"` 73 74 // Insecure is a flag to bypass server certificate validation 75 Insecure bool `yaml:"insecure,omitempty" json:"insecure,omitempty"` 76 } 77 78 // TLSCertificate has the x509 certificate PEM data with optional PEM private key 79 type TLSCertificate struct { 80 // Cert certificate (PEM) block 81 Cert string `yaml:"cert,omitempty" json:"cert,omitempty"` 82 83 // Key - keypair (PEM) block 84 Key string `yaml:"key,omitempty" json:"key,omitempty"` 85 } 86 87 // +genclient 88 // +genclient:noStatus 89 // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object 90 91 // VirtletImageMapping represents an ImageTranslation wrapped in k8s object. 92 type VirtletImageMapping struct { 93 meta_v1.TypeMeta `json:",inline"` 94 meta_v1.ObjectMeta `json:"metadata"` 95 Spec ImageTranslation `json:"spec"` 96 } 97 98 // ConfigName returns the name of the config. 99 func (vim *VirtletImageMapping) ConfigName() string { return vim.Name } 100 101 // Payload returns the actual translation for the mapping. 102 func (vim *VirtletImageMapping) Payload() (ImageTranslation, error) { 103 return vim.Spec, nil 104 } 105 106 // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object 107 108 // VirtletImageMappingList is a k8s representation of list of translation configs. 109 type VirtletImageMappingList struct { 110 meta_v1.TypeMeta `json:",inline"` 111 meta_v1.ListMeta `json:"metadata"` 112 Items []VirtletImageMapping `json:"items"` 113 }