github.com/alibaba/sealer@v0.8.6-0.20220430115802-37a2bdaa8173/build/buildimage/setter.go (about)

     1  // Copyright © 2022 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 buildimage
    16  
    17  import (
    18  	"fmt"
    19  
    20  	"github.com/alibaba/sealer/common"
    21  	v1 "github.com/alibaba/sealer/types/api/v1"
    22  	v2 "github.com/alibaba/sealer/types/api/v2"
    23  )
    24  
    25  type annotation struct {
    26  }
    27  
    28  func (a annotation) Set(ima *v1.Image) error {
    29  	return a.setClusterFile(ima)
    30  }
    31  
    32  func (a annotation) setClusterFile(ima *v1.Image) error {
    33  	var (
    34  		err error
    35  	)
    36  
    37  	cluster := &v2.Cluster{}
    38  	cluster.Kind = common.Kind
    39  	cluster.APIVersion = common.APIVersion
    40  	cluster.Name = "my-cluster"
    41  	cluster.Spec.SSH = v1.SSH{
    42  		Port: "22",
    43  		User: "root",
    44  	}
    45  
    46  	cluster.Spec.Image = ima.Name
    47  	err = setClusterFileToImage(cluster, ima)
    48  	if err != nil {
    49  		return fmt.Errorf("failed to set image metadata, err: %v", err)
    50  	}
    51  	return nil
    52  }
    53  
    54  func NewAnnotationSetter() ImageSetter {
    55  	return annotation{}
    56  }