Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename imported package alias #510

Merged
merged 1 commit into from
Nov 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions cmd/admission/app/options/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,10 @@ import (
"github.com/golang/glog"

"k8s.io/api/admissionregistration/v1beta1"
"k8s.io/client-go/kubernetes"

apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
admissionregistrationv1beta1client "k8s.io/client-go/kubernetes/typed/admissionregistration/v1beta1"
"k8s.io/client-go/kubernetes"
admissionregistrationv1beta1 "k8s.io/client-go/kubernetes/typed/admissionregistration/v1beta1"
)

const (
Expand Down Expand Up @@ -228,7 +227,7 @@ func RegisterWebhooks(c *Config, clienset *kubernetes.Clientset, cabundle []byte

}

func registerMutateWebhook(client admissionregistrationv1beta1client.MutatingWebhookConfigurationInterface,
func registerMutateWebhook(client admissionregistrationv1beta1.MutatingWebhookConfigurationInterface,
webhooks []v1beta1.MutatingWebhookConfiguration) error {
for _, hook := range webhooks {
existing, err := client.Get(hook.Name, metav1.GetOptions{})
Expand All @@ -251,7 +250,7 @@ func registerMutateWebhook(client admissionregistrationv1beta1client.MutatingWeb
return nil
}

func registerValidateWebhook(client admissionregistrationv1beta1client.ValidatingWebhookConfigurationInterface,
func registerValidateWebhook(client admissionregistrationv1beta1.ValidatingWebhookConfigurationInterface,
webhooks []v1beta1.ValidatingWebhookConfiguration) error {
for _, hook := range webhooks {
existing, err := client.Get(hook.Name, metav1.GetOptions{})
Expand Down
10 changes: 5 additions & 5 deletions cmd/admission/app/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ import (
"github.com/golang/glog"

"k8s.io/client-go/kubernetes"
restclient "k8s.io/client-go/rest"
appConf "volcano.sh/volcano/cmd/admission/app/options"
"k8s.io/client-go/rest"
"volcano.sh/volcano/cmd/admission/app/options"
"volcano.sh/volcano/pkg/client/clientset/versioned"
)

// GetClient Get a clientset with restConfig.
func GetClient(restConfig *restclient.Config) *kubernetes.Clientset {
func GetClient(restConfig *rest.Config) *kubernetes.Clientset {
clientset, err := kubernetes.NewForConfig(restConfig)
if err != nil {
glog.Fatal(err)
Expand All @@ -37,7 +37,7 @@ func GetClient(restConfig *restclient.Config) *kubernetes.Clientset {
}

// GetVolcanoClient get a clientset for volcano
func GetVolcanoClient(restConfig *restclient.Config) *versioned.Clientset {
func GetVolcanoClient(restConfig *rest.Config) *versioned.Clientset {
clientset, err := versioned.NewForConfig(restConfig)
if err != nil {
glog.Fatal(err)
Expand All @@ -48,7 +48,7 @@ func GetVolcanoClient(restConfig *restclient.Config) *versioned.Clientset {
// ConfigTLS is a helper function that generate tls certificates from directly defined tls config or kubeconfig
// These are passed in as command line for cluster certification. If tls config is passed in, we use the directly
// defined tls config, else use that defined in kubeconfig
func ConfigTLS(config *appConf.Config, restConfig *restclient.Config) *tls.Config {
func ConfigTLS(config *options.Config, restConfig *rest.Config) *tls.Config {
if len(config.CertFile) != 0 && len(config.KeyFile) != 0 {
sCert, err := tls.LoadX509KeyPair(config.CertFile, config.KeyFile)
if err != nil {
Expand Down
38 changes: 19 additions & 19 deletions cmd/admission/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,53 +29,53 @@ import (
"k8s.io/client-go/tools/clientcmd"

"volcano.sh/volcano/cmd/admission/app"
appConf "volcano.sh/volcano/cmd/admission/app/options"
admissioncontroller "volcano.sh/volcano/pkg/admission"
"volcano.sh/volcano/cmd/admission/app/options"
"volcano.sh/volcano/pkg/admission"
"volcano.sh/volcano/pkg/version"
)

func serveJobs(w http.ResponseWriter, r *http.Request) {
admissioncontroller.Serve(w, r, admissioncontroller.AdmitJobs)
admission.Serve(w, r, admission.AdmitJobs)
}

func serveMutateJobs(w http.ResponseWriter, r *http.Request) {
admissioncontroller.Serve(w, r, admissioncontroller.MutateJobs)
admission.Serve(w, r, admission.MutateJobs)
}

func main() {
config := appConf.NewConfig()
config := options.NewConfig()
config.AddFlags()
flag.Parse()

if config.PrintVersion {
version.PrintVersionAndExit()
}

http.HandleFunc(admissioncontroller.AdmitJobPath, serveJobs)
http.HandleFunc(admissioncontroller.MutateJobPath, serveMutateJobs)
http.HandleFunc(admission.AdmitJobPath, serveJobs)
http.HandleFunc(admission.MutateJobPath, serveMutateJobs)

if err := config.CheckPortOrDie(); err != nil {
glog.Fatalf("Configured port is invalid: %v\n", err)
glog.Fatalf("Configured port is invalid: %v", err)
}
addr := ":" + strconv.Itoa(config.Port)

restConfig, err := clientcmd.BuildConfigFromFlags(config.Master, config.Kubeconfig)
if err != nil {
glog.Fatalf("Unable to build k8s config: %v\n", err)
glog.Fatalf("Unable to build k8s config: %v", err)
}

admissioncontroller.VolcanoClientSet = app.GetVolcanoClient(restConfig)
admission.VolcanoClientSet = app.GetVolcanoClient(restConfig)

servePods(config)

caBundle, err := ioutil.ReadFile(config.CaCertFile)
if err != nil {
glog.Fatalf("Unable to read cacert file: %v\n", err)
glog.Fatalf("Unable to read cacert file: %v", err)
}

err = appConf.RegisterWebhooks(config, app.GetClient(restConfig), caBundle)
err = options.RegisterWebhooks(config, app.GetClient(restConfig), caBundle)
if err != nil {
glog.Fatalf("Unable to register webhook configs: %v\n", err)
glog.Fatalf("Unable to register webhook configs: %v", err)
}

stopChannel := make(chan os.Signal)
Expand All @@ -89,28 +89,28 @@ func main() {
go func() {
err = server.ListenAndServeTLS("", "")
if err != nil && err != http.ErrServerClosed {
glog.Fatalf("ListenAndServeTLS for admission webhook failed: %v\n", err)
glog.Fatalf("ListenAndServeTLS for admission webhook failed: %v", err)
close(webhookServeError)
}
}()

select {
case <-stopChannel:
if err := server.Close(); err != nil {
glog.Fatalf("Close admission server failed: %v\n", err)
glog.Fatalf("Close admission server failed: %v", err)
}
return
case <-webhookServeError:
return
}
}

func servePods(config *appConf.Config) {
admController := &admissioncontroller.Controller{
VcClients: admissioncontroller.VolcanoClientSet,
func servePods(config *options.Config) {
admController := &admission.Controller{
VcClients: admission.VolcanoClientSet,
SchedulerName: config.SchedulerName,
}
http.HandleFunc(admissioncontroller.AdmitPodPath, admController.ServerPods)
http.HandleFunc(admission.AdmitPodPath, admController.ServerPods)

return
}
File renamed without changes.
18 changes: 9 additions & 9 deletions cmd/controllers/app/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
"k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/util/uuid"
"k8s.io/client-go/informers"
clientset "k8s.io/client-go/kubernetes"
kubeclientset "k8s.io/client-go/kubernetes"
"k8s.io/client-go/kubernetes/scheme"
corev1 "k8s.io/client-go/kubernetes/typed/core/v1"

Expand All @@ -41,7 +41,7 @@ import (

"volcano.sh/volcano/cmd/controllers/app/options"
"volcano.sh/volcano/pkg/apis/helpers"
vkclient "volcano.sh/volcano/pkg/client/clientset/versioned"
vcclientset "volcano.sh/volcano/pkg/client/clientset/versioned"
"volcano.sh/volcano/pkg/controllers/garbagecollector"
"volcano.sh/volcano/pkg/controllers/job"
"volcano.sh/volcano/pkg/controllers/podgroup"
Expand Down Expand Up @@ -92,7 +92,7 @@ func Run(opt *options.ServerOption) error {
return fmt.Errorf("finished without leader elect")
}

leaderElectionClient, err := clientset.NewForConfig(rest.AddUserAgent(config, "leader-election"))
leaderElectionClient, err := kubeclientset.NewForConfig(rest.AddUserAgent(config, "leader-election"))
if err != nil {
return err
}
Expand Down Expand Up @@ -138,15 +138,15 @@ func Run(opt *options.ServerOption) error {

func startControllers(config *rest.Config, opt *options.ServerOption) func(ctx context.Context) {
// TODO: add user agent for different controllers
kubeClient := clientset.NewForConfigOrDie(config)
vkClient := vkclient.NewForConfigOrDie(config)
kubeClient := kubeclientset.NewForConfigOrDie(config)
vcClient := vcclientset.NewForConfigOrDie(config)

sharedInformers := informers.NewSharedInformerFactory(kubeClient, 0)

jobController := job.NewJobController(kubeClient, vkClient, sharedInformers, opt.WorkerThreads)
queueController := queue.NewQueueController(kubeClient, vkClient)
garbageCollector := garbagecollector.NewGarbageCollector(vkClient)
pgController := podgroup.NewPodgroupController(kubeClient, vkClient, sharedInformers, opt.SchedulerName)
jobController := job.NewJobController(kubeClient, vcClient, sharedInformers, opt.WorkerThreads)
queueController := queue.NewQueueController(kubeClient, vcClient)
garbageCollector := garbagecollector.NewGarbageCollector(vcClient)
pgController := podgroup.NewPodgroupController(kubeClient, vcClient, sharedInformers, opt.SchedulerName)

return func(ctx context.Context) {
go jobController.Run(ctx.Done())
Expand Down
Binary file modified example/huawei-connection/Volcano-intro.pptx
Binary file not shown.
70 changes: 35 additions & 35 deletions pkg/admission/admission_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ import (
"k8s.io/apimachinery/pkg/util/validation/field"

"k8s.io/kubernetes/pkg/apis/core/validation"
"volcano.sh/volcano/pkg/apis/batch/v1alpha1"
vcver "volcano.sh/volcano/pkg/client/clientset/versioned"
batchv1alpha1 "volcano.sh/volcano/pkg/apis/batch/v1alpha1"
vcclientset "volcano.sh/volcano/pkg/client/clientset/versioned"
)

const (
Expand All @@ -53,7 +53,7 @@ type AdmitFunc func(v1beta1.AdmissionReview) *v1beta1.AdmissionResponse

// Controller the Admission Controller type
type Controller struct {
VcClients vcver.Interface
VcClients vcclientset.Interface
SchedulerName string
}

Expand All @@ -64,26 +64,26 @@ var scheme = runtime.NewScheme()
var Codecs = serializer.NewCodecFactory(scheme)

// policyEventMap defines all policy events and whether to allow external use
var policyEventMap = map[v1alpha1.Event]bool{
v1alpha1.AnyEvent: true,
v1alpha1.PodFailedEvent: true,
v1alpha1.PodEvictedEvent: true,
v1alpha1.JobUnknownEvent: true,
v1alpha1.TaskCompletedEvent: true,
v1alpha1.OutOfSyncEvent: false,
v1alpha1.CommandIssuedEvent: false,
var policyEventMap = map[batchv1alpha1.Event]bool{
batchv1alpha1.AnyEvent: true,
batchv1alpha1.PodFailedEvent: true,
batchv1alpha1.PodEvictedEvent: true,
batchv1alpha1.JobUnknownEvent: true,
batchv1alpha1.TaskCompletedEvent: true,
batchv1alpha1.OutOfSyncEvent: false,
batchv1alpha1.CommandIssuedEvent: false,
}

// policyActionMap defines all policy actions and whether to allow external use
var policyActionMap = map[v1alpha1.Action]bool{
v1alpha1.AbortJobAction: true,
v1alpha1.RestartJobAction: true,
v1alpha1.RestartTaskAction: true,
v1alpha1.TerminateJobAction: true,
v1alpha1.CompleteJobAction: true,
v1alpha1.ResumeJobAction: true,
v1alpha1.SyncJobAction: false,
v1alpha1.EnqueueAction: false,
var policyActionMap = map[batchv1alpha1.Action]bool{
batchv1alpha1.AbortJobAction: true,
batchv1alpha1.RestartJobAction: true,
batchv1alpha1.RestartTaskAction: true,
batchv1alpha1.TerminateJobAction: true,
batchv1alpha1.CompleteJobAction: true,
batchv1alpha1.ResumeJobAction: true,
batchv1alpha1.SyncJobAction: false,
batchv1alpha1.EnqueueAction: false,
}

func init() {
Expand All @@ -106,10 +106,10 @@ func ToAdmissionResponse(err error) *v1beta1.AdmissionResponse {
}

//DecodeJob decodes the job using deserializer from the raw object
func DecodeJob(object runtime.RawExtension, resource metav1.GroupVersionResource) (v1alpha1.Job, error) {
jobResource := metav1.GroupVersionResource{Group: v1alpha1.SchemeGroupVersion.Group, Version: v1alpha1.SchemeGroupVersion.Version, Resource: "jobs"}
func DecodeJob(object runtime.RawExtension, resource metav1.GroupVersionResource) (batchv1alpha1.Job, error) {
jobResource := metav1.GroupVersionResource{Group: batchv1alpha1.SchemeGroupVersion.Group, Version: batchv1alpha1.SchemeGroupVersion.Version, Resource: "jobs"}
raw := object.Raw
job := v1alpha1.Job{}
job := batchv1alpha1.Job{}

if resource != jobResource {
err := fmt.Errorf("expect resource to be %s", jobResource)
Expand All @@ -125,9 +125,9 @@ func DecodeJob(object runtime.RawExtension, resource metav1.GroupVersionResource
return job, nil
}

func validatePolicies(policies []v1alpha1.LifecyclePolicy, fldPath *field.Path) error {
func validatePolicies(policies []batchv1alpha1.LifecyclePolicy, fldPath *field.Path) error {
var err error
policyEvents := map[v1alpha1.Event]struct{}{}
policyEvents := map[batchv1alpha1.Event]struct{}{}
exitCodes := map[int32]struct{}{}

for _, policy := range policies {
Expand Down Expand Up @@ -182,14 +182,14 @@ func validatePolicies(policies []v1alpha1.LifecyclePolicy, fldPath *field.Path)
}
}

if _, found := policyEvents[v1alpha1.AnyEvent]; found && len(policyEvents) > 1 {
if _, found := policyEvents[batchv1alpha1.AnyEvent]; found && len(policyEvents) > 1 {
err = multierror.Append(err, fmt.Errorf("if there's * here, no other policy should be here"))
}

return err
}

func getEventList(policy v1alpha1.LifecyclePolicy) []v1alpha1.Event {
func getEventList(policy batchv1alpha1.LifecyclePolicy) []batchv1alpha1.Event {
policyEventsList := policy.Events
if len(policy.Event) > 0 {
policyEventsList = append(policyEventsList, policy.Event)
Expand All @@ -198,9 +198,9 @@ func getEventList(policy v1alpha1.LifecyclePolicy) []v1alpha1.Event {
return uniquePolicyEventlist
}

func removeDuplicates(EventList []v1alpha1.Event) []v1alpha1.Event {
keys := make(map[v1alpha1.Event]bool)
list := []v1alpha1.Event{}
func removeDuplicates(EventList []batchv1alpha1.Event) []batchv1alpha1.Event {
keys := make(map[batchv1alpha1.Event]bool)
list := []batchv1alpha1.Event{}
for _, val := range EventList {
if _, value := keys[val]; !value {
keys[val] = true
Expand All @@ -210,8 +210,8 @@ func removeDuplicates(EventList []v1alpha1.Event) []v1alpha1.Event {
return list
}

func getValidEvents() []v1alpha1.Event {
var events []v1alpha1.Event
func getValidEvents() []batchv1alpha1.Event {
var events []batchv1alpha1.Event
for e, allow := range policyEventMap {
if allow {
events = append(events, e)
Expand All @@ -221,8 +221,8 @@ func getValidEvents() []v1alpha1.Event {
return events
}

func getValidActions() []v1alpha1.Action {
var actions []v1alpha1.Action
func getValidActions() []batchv1alpha1.Action {
var actions []batchv1alpha1.Action
for a, allow := range policyActionMap {
if allow {
actions = append(actions, a)
Expand All @@ -233,7 +233,7 @@ func getValidActions() []v1alpha1.Action {
}

// ValidateIO validate IO configuration
func ValidateIO(volumes []v1alpha1.VolumeSpec) (string, bool) {
func ValidateIO(volumes []batchv1alpha1.VolumeSpec) (string, bool) {
volumeMap := map[string]bool{}
for _, volume := range volumes {
if len(volume.MountPath) == 0 {
Expand Down
5 changes: 3 additions & 2 deletions pkg/admission/admit_job.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,13 @@ import (
k8scorevalid "k8s.io/kubernetes/pkg/apis/core/validation"

"volcano.sh/volcano/pkg/apis/batch/v1alpha1"
"volcano.sh/volcano/pkg/client/clientset/versioned"
vcclientset "volcano.sh/volcano/pkg/client/clientset/versioned"
"volcano.sh/volcano/pkg/controllers/job/plugins"
)

// VolcanoClientSet is volcano clientset
var VolcanoClientSet versioned.Interface
// TODO: make it as package local var.
var VolcanoClientSet vcclientset.Interface

// AdmitJobs is to admit jobs and return response
func AdmitJobs(ar v1beta1.AdmissionReview) *v1beta1.AdmissionResponse {
Expand Down
Loading