func BuildJuju(
	opts config.AutoscalingOptions,
	do cloudprovider.NodeGroupDiscoveryOptions,
	rl *cloudprovider.ResourceLimiter,
) cloudprovider.CloudProvider {
	flag.Parse()
	kubeClient := createKubeClient(getKubeConfig())

	var configRC io.ReadCloser
	if opts.CloudConfig != "" {
		var err error
		configRC, err = os.Open(opts.CloudConfig)
		if err != nil {
			klog.Fatalf("Couldn't open cloud provider configuration %s: %#v", opts.CloudConfig, err)
		}
		defer configRC.Close()
	}

	jujuConfig, err := readCloudConfigYaml(configRC)
	if err != nil {
		klog.Fatalf("Couldn't read cloud provider configuration yaml file %s", err)
	}

	ngs := []cloudprovider.NodeGroup{}
	for _, nodeGroupSpecString := range do.NodeGroupSpecs {
		nodeGroupSpec, err := dynamic.SpecFromString(nodeGroupSpecString, scaleToZeroSupported)
		if err != nil {
			klog.Errorf("failed to parse node group spec: %v", err)
			continue
		}
		model, application, err := parseNodeGroupName(nodeGroupSpec.Name)
		if err != nil {
			klog.Errorf("failed to parse node group name: %v", err)
			continue
		}

		connector, err := connector.NewSimple(connector.SimpleConfig{
			ControllerAddresses: jujuConfig.Endpoints,
			CACert:              jujuConfig.CAcert,
			ModelUUID:           model,
			Username:            jujuConfig.User,
			Password:            jujuConfig.Password,
		})

		if err != nil {
			klog.Errorf("failed to create simple connector %v", err)
			continue
		}

		jujuAPI, err := NewJujuAPi(connector)
		if err != nil {
			klog.Errorf("failed to create JujuClient %v", err)
			continue
		}

		man, err := NewManager(jujuAPI, kubeClient, model, application)
		if err != nil {
			klog.Errorf("error creating manager: %v", err)
			continue
		}

		jujuID := fmt.Sprintf("juju-%s-%s", model, application)
		ng := &NodeGroup{
			id:      jujuID,
			minSize: nodeGroupSpec.MinSize,
			maxSize: nodeGroupSpec.MaxSize,
			target:  len(man.units),
			manager: man,
		}
		ngs = append(ngs, ng)
	}

	provider, err := newJujuCloudProvider(rl, ngs)
	if err != nil {
		klog.Fatalf("Failed to create Juju cloud provider: %v", err)
	}

	return provider
}
// BuildJuju builds the Juju cloud provider.
BuildJuju builds the Juju cloud provider.
// BuildJuju builds the Juju cloud provider .
func BuildJuju(
	opts config.AutoscalingOptions,
	do cloudprovider.NodeGroupDiscoveryOptions,
	rl *cloudprovider.ResourceLimiter,
) cloudprovider.CloudProvider {
	flag.Parse()
	kubeClient := createKubeClient(getKubeConfig())
	var configRC io.ReadCloser
	if opts.CloudConfig != "" {
		var err error
		configRC, err = os.Open(opts.CloudConfig)
		if err != nil {
			klog.Fatalf("Couldn't open cloud provider configuration %s: %#v", opts.CloudConfig, err)
		}
		defer configRC.Close()
	}
	jujuConfig, err := readCloudConfigYaml(configRC)
	if err != nil {
		klog.Fatalf("Couldn't read cloud provider configuration yaml file %s", err)
	}
	ngs := []cloudprovider.NodeGroup{}
	for _, nodeGroupSpecString := range do.NodeGroupSpecs {
		nodeGroupSpec, err := dynamic.SpecFromString(nodeGroupSpecString, scaleToZeroSupported)
		if err != nil {
			klog.Errorf("failed to parse node group spec: %v", err)
			continue
		}
		model, application, err := parseNodeGroupName(nodeGroupSpec.Name)
		if err != nil {
			klog.Errorf("failed to parse node group name: %v", err)
			continue
		}
		connector, err := connector.NewSimple(connector.SimpleConfig{
			ControllerAddresses: jujuConfig.Endpoints,
			CACert:              jujuConfig.CAcert,
			ModelUUID:           model,
			Username:            jujuConfig.User,
			Password:            jujuConfig.Password,
		})
		if err != nil {
			klog.Errorf("failed to create simple connector %v", err)
			continue
		}
		jujuAPI, err := NewJujuAPi(connector)
		if err != nil {
			klog.Errorf("failed to create JujuClient %v", err)
			continue
		}
		man, err := NewManager(jujuAPI, kubeClient, model, application)
		if err != nil {
			klog.Errorf("error creating manager: %v", err)
			continue
		}
		jujuID := fmt.Sprintf("juju-%s-%s", model, application)
		ng := &NodeGroup{
			id:      jujuID,
			minSize: nodeGroupSpec.MinSize,
			maxSize: nodeGroupSpec.MaxSize,
			target:  len(man.units),
			manager: man,
		}
		ngs = append(ngs, ng)
	}
	provider, err := newJujuCloudProvider(rl, ngs)
	if err != nil {
		klog.Fatalf("Failed to create Juju cloud provider: %v", err)
	}
	return provider
}
func BuildJuju ( opts config . AutoscalingOptions , do cloudprovider . NodeGroupDiscoveryOptions , rl * cloudprovider . ResourceLimiter , ) cloudprovider . CloudProvider { flag . Parse ( ) kubeClient := createKubeClient ( getKubeConfig ( ) ) var configRC io . ReadCloser if opts . CloudConfig != " " { var err error configRC , err = os . Open ( opts . CloudConfig ) if err != nil { klog . Fatalf ( " " , opts . CloudConfig , err ) } defer configRC . Close ( ) } jujuConfig , err := readCloudConfigYaml ( configRC ) if err != nil { klog . Fatalf ( " " , err ) } ngs := [ ] cloudprovider . NodeGroup { } for _ , nodeGroupSpecString := range do . NodeGroupSpecs { nodeGroupSpec , err := dynamic . SpecFromString ( nodeGroupSpecString , scaleToZeroSupported ) if err != nil { klog . Errorf ( " " , err ) continue } model , application , err := parseNodeGroupName ( nodeGroupSpec . Name ) if err != nil { klog . Errorf ( " " , err ) continue } connector , err := connector . NewSimple ( connector . SimpleConfig { ControllerAddresses : jujuConfig . Endpoints , CACert : jujuConfig . CAcert , ModelUUID : model , Username : jujuConfig . User , Password : jujuConfig . Password , } ) if err != nil { klog . Errorf ( " " , err ) continue } jujuAPI , err := NewJujuAPi ( connector ) if err != nil { klog . Errorf ( " " , err ) continue } man , err := NewManager ( jujuAPI , kubeClient , model , application ) if err != nil { klog . Errorf ( " " , err ) continue } jujuID := fmt . Sprintf ( " " , model , application ) ng := & NodeGroup { id : jujuID , minSize : nodeGroupSpec . MinSize , maxSize : nodeGroupSpec . MaxSize , target : len ( man . units ) , manager : man , } ngs = append ( ngs , ng ) } provider , err := newJujuCloudProvider ( rl , ngs ) if err != nil { klog . Fatalf ( " " , err ) } return provider }
BuildJuju builds the Juju cloud provider.
BuildJuju builds the Juju cloud provider .