github.com/sealerio/sealer@v0.11.1-0.20240507115618-f4f89c5853ae/types/api/v1/image_types.go (about)

     1  // Copyright © 2021 Alibaba Group Holding Ltd.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package v1
    16  
    17  import (
    18  	"strings"
    19  
    20  	"github.com/opencontainers/go-digest"
    21  	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
    22  )
    23  
    24  // EDIT THIS FILE!  THIS IS SCAFFOLDING FOR YOU TO OWN!
    25  // NOTE: json tags are required.  Any new fields you add must have json tags for the fields to be serialized.
    26  
    27  type Layer struct {
    28  	ID    digest.Digest `json:"id,omitempty"` // shaxxx:d6a6c9bfd4ad2901695be1dceca62e1c35a8482982ad6be172fe6958bc4f79d7
    29  	Type  string        `json:"type,omitempty"`
    30  	Value string        `json:"value,omitempty"`
    31  }
    32  
    33  // ImageSpec defines the desired state of Image
    34  type ImageSpec struct {
    35  	// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
    36  	// Important: Run "make" to regenerate code after modifying this file
    37  
    38  	// Foo is an example field of Image. Edit Image_types.go to remove/update
    39  	ID            string      `json:"id,omitempty"`
    40  	Layers        []Layer     `json:"layers,omitempty"`
    41  	SealerVersion string      `json:"sealer_version,omitempty"`
    42  	Platform      Platform    `json:"platform"`
    43  	ImageConfig   ImageConfig `json:"image_config"`
    44  }
    45  
    46  // ImageStatus defines the observed state of Image
    47  type ImageStatus struct {
    48  	// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
    49  	// Important: Run "make" to regenerate code after modifying this file
    50  }
    51  
    52  // +kubebuilder:object:root=true
    53  // +kubebuilder:subresource:status
    54  // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
    55  
    56  // Image is the Schema for the images API
    57  type Image struct {
    58  	metav1.TypeMeta   `json:",inline" yaml:",inline"`
    59  	metav1.ObjectMeta `json:"metadata,omitempty" yaml:"metadata,omitempty"`
    60  
    61  	Spec   ImageSpec   `json:"spec,omitempty"  yaml:"spec,omitempty"`
    62  	Status ImageStatus `json:"status,omitempty"  yaml:"status,omitempty"`
    63  }
    64  
    65  // +kubebuilder:object:root=true
    66  // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
    67  
    68  // ImageList contains a list of Image
    69  type ImageList struct {
    70  	metav1.TypeMeta `json:",inline"`
    71  	metav1.ListMeta `json:"metadata,omitempty"`
    72  	Items           []Image `json:"items,omitempty"`
    73  }
    74  
    75  type ImageConfig struct {
    76  	// define this image is application image or normal image.
    77  	ImageType string            `json:"image_type,omitempty"`
    78  	Cmd       ImageCmd          `json:"cmd,omitempty"`
    79  	Args      ImageArg          `json:"args,omitempty"`
    80  	Labels    map[string]string `json:"labels,omitempty"`
    81  }
    82  
    83  type ImageCmd struct {
    84  	//cmd list of base image
    85  	Parent []string `json:"parent,omitempty"`
    86  	//cmd list of current image
    87  	Current []string `json:"current,omitempty"`
    88  }
    89  
    90  type ImageArg struct {
    91  	//arg set of base image
    92  	Parent map[string]string `json:"parent,omitempty"`
    93  	//arg set of current image
    94  	Current map[string]string `json:"current,omitempty"`
    95  }
    96  
    97  type Platform struct {
    98  	Architecture string `json:"architecture,omitempty"`
    99  	OS           string `json:"os,omitempty"`
   100  	// Variant is an optional field specifying a variant of the CPU, for
   101  	// example `v7` to specify ARMv7 when architecture is `arm`.
   102  	Variant string `json:"variant,omitempty"`
   103  }
   104  
   105  func (p *Platform) ToString() string {
   106  	str := p.OS + "/" + p.Architecture + "/" + p.Variant
   107  	str = strings.TrimSuffix(str, "/")
   108  	str = strings.TrimPrefix(str, "/")
   109  	return str
   110  }
   111  
   112  func init() {
   113  	SchemeBuilder.Register(&Image{}, &ImageList{})
   114  }