github.com/sealerio/sealer@v0.11.1-0.20240507115618-f4f89c5853ae/pkg/registry/configurator.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 registry
    16  
    17  import (
    18  	"fmt"
    19  	"net"
    20  
    21  	containerruntime "github.com/sealerio/sealer/pkg/container-runtime"
    22  	"github.com/sealerio/sealer/pkg/imagedistributor"
    23  	"github.com/sealerio/sealer/pkg/infradriver"
    24  	v2 "github.com/sealerio/sealer/types/api/v2"
    25  )
    26  
    27  type LocalRegistryInfo struct {
    28  	*v2.LocalRegistry
    29  	DeployHosts []net.IP `json:"deployHosts,omitempty"`
    30  	Vip         string   `json:"vip,omitempty"`
    31  }
    32  
    33  type RegistryInfo struct { // nolint
    34  	External *v2.ExternalRegistry `json:"external,omitempty"`
    35  	Local    LocalRegistryInfo    `json:"local,omitempty"`
    36  }
    37  
    38  // Configurator provide registry configuration management
    39  type Configurator interface {
    40  	// InstallOn will install registry configuration on each given hosts.
    41  	InstallOn(masters, nodes []net.IP) error
    42  
    43  	// UninstallFrom will uninstall registry configuration on each given hosts.
    44  	UninstallFrom(masters, nodes []net.IP) error
    45  
    46  	GetDriver() (Driver, error)
    47  
    48  	GetRegistryInfo() RegistryInfo
    49  }
    50  
    51  func NewConfigurator(deployHosts []net.IP,
    52  	containerRuntimeInfo containerruntime.Info,
    53  	regConfig v2.Registry,
    54  	infraDriver infradriver.InfraDriver,
    55  	distributor imagedistributor.Distributor) (Configurator, error) {
    56  	if regConfig.LocalRegistry != nil {
    57  		return &localConfigurator{
    58  			deployHosts:          deployHosts,
    59  			infraDriver:          infraDriver,
    60  			LocalRegistry:        regConfig.LocalRegistry,
    61  			containerRuntimeInfo: containerRuntimeInfo,
    62  			distributor:          distributor,
    63  		}, nil
    64  	}
    65  
    66  	if regConfig.ExternalRegistry != nil {
    67  		return NewExternalConfigurator(
    68  			regConfig.ExternalRegistry,
    69  			containerRuntimeInfo,
    70  			infraDriver,
    71  		)
    72  	}
    73  
    74  	return nil, fmt.Errorf("unsupported registry type")
    75  }