// Copyright 2017 PingCAP, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// See the License for the specific language governing permissions and
// limitations under the License.package spec

package manager

import (
	"github.com/ngaut/log"
	"github.com/pingcap/tidb-cloud-manager/pkg/client"
	"k8s.io/api/core/v1"
)

func New(kubeconfig string, serviceType string, ns string) *Manager {
	cli, err := client.New(kubeconfig)
	if err != nil {
		log.Fatalf("failed to initialize kube client, error: %v", err)
	}
	st := "ClusterIP"
	switch serviceType {
	case string(v1.ServiceTypeClusterIP), string(v1.ServiceTypeNodePort), string(v1.ServiceTypeLoadBalancer):
		st = serviceType
	default:
		log.Warnf("wrong ServiceType %s, use default %s", serviceType, st)
	}
	return &Manager{
		ServiceType: st,
		Cli:         cli,
		Namespace:   ns,
	}
}
