diff --git a/pkg/client/queuejob.go b/pkg/client/queuejob.go deleted file mode 100644 index 93c1492d2..000000000 --- a/pkg/client/queuejob.go +++ /dev/null @@ -1,87 +0,0 @@ -/* -Copyright 2019, 2021, 2022, 2023 The Multi-Cluster App Dispatcher Authors. - -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, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package client - -import ( - "context" - "fmt" - "os" - "time" - - arbv1 "github.com/project-codeflare/multi-cluster-app-dispatcher/pkg/apis/controller/v1beta1" - - apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" - apiextensionsclient "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/util/errors" - "k8s.io/apimachinery/pkg/util/wait" - "k8s.io/klog/v2" - "sigs.k8s.io/yaml" -) - -const AppWrapperCrdPath = "config/crd/bases/mcad.ibm.com_appwrappers.yaml" -const appWrapperKindName = arbv1.AppWrapperPlural + "." + arbv1.GroupName - -func CreateAppWrapperKind(clientset apiextensionsclient.Interface) (*apiextensionsv1.CustomResourceDefinition, error) { - f, err := os.ReadFile(AppWrapperCrdPath) - if err != nil { - return nil, fmt.Errorf("cannot load the CRD from file %s: %v", AppWrapperCrdPath, err) - } - - crd := &apiextensionsv1.CustomResourceDefinition{} - err = yaml.Unmarshal(f, crd) - if err != nil { - return nil, fmt.Errorf("cannot unmarshal the CRD: %v", err) - } - - _, err = clientset.ApiextensionsV1().CustomResourceDefinitions().Create(context.Background(), crd, metav1.CreateOptions{}) - if err != nil { - return nil, err - } - - // wait for CRD being established - err = wait.Poll(500*time.Millisecond, 60*time.Second, func() (bool, error) { - crd, err = clientset.ApiextensionsV1().CustomResourceDefinitions().Get(context.Background(), appWrapperKindName, metav1.GetOptions{}) - if err != nil { - return false, err - } - for _, cond := range crd.Status.Conditions { - switch cond.Type { - case apiextensionsv1.Established: - if cond.Status == apiextensionsv1.ConditionTrue { - return true, err - } - case apiextensionsv1.NamesAccepted: - if cond.Status == apiextensionsv1.ConditionFalse { - fmt.Printf("Name conflict: %v\n", cond.Reason) - } - } - } - return false, err - }) - if err != nil { - deleteErr := clientset.ApiextensionsV1().CustomResourceDefinitions().Delete(context.Background(), appWrapperKindName, metav1.DeleteOptions{}) - if deleteErr != nil { - return nil, errors.NewAggregate([]error{err, deleteErr}) - } - return nil, err - } - - klog.V(4).Infof("AppWrapper CRD was created.") - - return crd, nil -} diff --git a/pkg/controller/queuejob/queuejob_controller_ex.go b/pkg/controller/queuejob/queuejob_controller_ex.go index 8f1a71f8e..612a3cb7b 100644 --- a/pkg/controller/queuejob/queuejob_controller_ex.go +++ b/pkg/controller/queuejob/queuejob_controller_ex.go @@ -1406,11 +1406,8 @@ func (qjm *XController) backoff(ctx context.Context, q *arbv1.AppWrapper, reason qjm.serverOption.BackoffTime, qjm.qjqueue.IfExistActiveQ(q), qjm.qjqueue.IfExistUnschedulableQ(q), q, q.ResourceVersion, q.Status) } -// Run start AppWrapper Controller +// Run starts AppWrapper Controller func (cc *XController) Run(stopCh chan struct{}) { - // initialized - createAppWrapperKind(cc.config) - go cc.appwrapperInformer.Informer().Run(stopCh) go cc.qjobResControls[arbv1.ResourceTypePod].Run(stopCh) diff --git a/pkg/controller/queuejob/utils.go b/pkg/controller/queuejob/utils.go index 5e647e974..f8b680e15 100644 --- a/pkg/controller/queuejob/utils.go +++ b/pkg/controller/queuejob/utils.go @@ -18,13 +18,9 @@ package queuejob import ( corev1 "k8s.io/api/core/v1" - apiextensionsclient "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset" - apierrors "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/client-go/rest" arbv1 "github.com/project-codeflare/multi-cluster-app-dispatcher/pkg/apis/controller/v1beta1" - "github.com/project-codeflare/multi-cluster-app-dispatcher/pkg/client" ) func GetXQJFullName(qj *arbv1.AppWrapper) string { @@ -37,18 +33,6 @@ func HigherSystemPriorityQJ(qj1, qj2 interface{}) bool { return qj1.(*arbv1.AppWrapper).Status.SystemPriority > qj2.(*arbv1.AppWrapper).Status.SystemPriority } -func createAppWrapperKind(config *rest.Config) error { - extensionscs, err := apiextensionsclient.NewForConfig(config) - if err != nil { - return err - } - _, err = client.CreateAppWrapperKind(extensionscs) - if err != nil && !apierrors.IsAlreadyExists(err) { - return err - } - return nil -} - // GenerateAppWrapperCondition returns condition of a AppWrapper condition. func GenerateAppWrapperCondition(condType arbv1.AppWrapperConditionType, condStatus corev1.ConditionStatus, condReason string, condMsg string) arbv1.AppWrapperCondition { return arbv1.AppWrapperCondition{