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

pod convert policy code cleanup in main #547

Merged
merged 1 commit into from
May 15, 2024
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
2 changes: 1 addition & 1 deletion deploy/crds/kosmos.io_clusterpodconvertpolicies.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ spec:
shortNames:
- cpcp
singular: clusterpodconvertpolicy
scope: Namespaced
scope: Cluster
versions:
- name: v1alpha1
schema:
Expand Down
4 changes: 2 additions & 2 deletions pkg/kosmosctl/install/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -654,8 +654,8 @@ func (o *CommandInstallOptions) createControlCluster() error {
return fmt.Errorf("kosmosctl install run error, get control panel cluster failed: %s", err)
}
} else {
// 'kosmos-control-cluster' has been created, only need to create serviceExport and serviceImport
err = joinOptions.CreateServiceExportAndImport()
// 'kosmos-control-cluster' has been created, only need to create related crds
err = joinOptions.CreateTreeRelatedCRDs()
if err != nil {
return fmt.Errorf("kosmosctl install run error, join control panel cluster failed: %s", err)
}
Expand Down
32 changes: 28 additions & 4 deletions pkg/kosmosctl/join/join.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,8 @@ func (o *CommandJoinOptions) Run(args []string) error {
return nil
}

// CreateServiceExportAndImport only enable tree, create serviceExport and serviceImport
func (o *CommandJoinOptions) CreateServiceExportAndImport() error {
// CreateTreeRelatedCRDs only enable tree, create related crds
func (o *CommandJoinOptions) CreateTreeRelatedCRDs() error {
serviceExport, err := util.GenerateCustomResourceDefinition(manifest.ServiceExport, nil)
if err != nil {
return err
Expand All @@ -272,6 +272,30 @@ func (o *CommandJoinOptions) CreateServiceExportAndImport() error {
}
klog.Info("Create CRD " + serviceImport.Name + " successful.")

clusterPodConvert, err := util.GenerateCustomResourceDefinition(manifest.ClusterPodConvert, nil)
if err != nil {
return err
}
_, err = o.K8sExtensionsClient.ApiextensionsV1().CustomResourceDefinitions().Create(context.Background(), clusterPodConvert, metav1.CreateOptions{})
if err != nil {
if !apierrors.IsAlreadyExists(err) {
return fmt.Errorf("kosmosctl join run error, crd options failed: %v", err)
}
}
klog.Info("Create CRD " + clusterPodConvert.Name + " successful.")

podConvert, err := util.GenerateCustomResourceDefinition(manifest.PodConvert, nil)
if err != nil {
return err
}
_, err = o.K8sExtensionsClient.ApiextensionsV1().CustomResourceDefinitions().Create(context.Background(), podConvert, metav1.CreateOptions{})
if err != nil {
if !apierrors.IsAlreadyExists(err) {
return fmt.Errorf("kosmosctl join run error, crd options failed: %v", err)
}
}
klog.Info("Create CRD " + podConvert.Name + " successful.")

return nil
}

Expand Down Expand Up @@ -333,8 +357,8 @@ func (o *CommandJoinOptions) runCluster() error {
}

if o.EnableTree {
// create serviceExport and serviceImport
err := o.CreateServiceExportAndImport()
// create ClusterTree related crds
err := o.CreateTreeRelatedCRDs()
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/kubenest/controller/kosmos/kosmos_join_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ func (c *KosmosJoinController) CreateCluster(ctx context.Context, request reconc
// create crd cluster.kosmos.io
klog.Infof("Attempting to create kosmos-clustertree CRDs for virtualcluster %s/%s...", request.Namespace, request.Name)
for _, crdToCreate := range []string{file.ServiceImport, file.Cluster,
file.ServiceExport, file.PodConversionCRD, file.PodConvertPolicyCRD} {
file.ServiceExport, file.ClusterPodConvert, file.PodConvert} {
crdObject, err := kosmosctl.GenerateCustomResourceDefinition(crdToCreate, nil)
if err != nil {
return err
Expand Down
14 changes: 7 additions & 7 deletions pkg/utils/podutils/pod_convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func ConvertPod(pod *corev1.Pod, cpcp []kosmosv1alpha1.ClusterPodConvertPolicy,
convertSchedulerName(pod, converters.SchedulerNameConverter)
convertNodeName(pod, converters.NodeNameConverter)
convertNodeSelector(pod, converters.NodeSelectorConverter)
converToleration(pod, converters.TolerationConverter)
convertToleration(pod, converters.TolerationConverter)
convertAffinity(pod, converters.AffinityConverter)
convertTopologySpreadConstraints(pod, converters.TopologySpreadConstraintsConverter)
convertHostAliases(pod, converters.HostAliasesConverter)
Expand Down Expand Up @@ -94,22 +94,22 @@ func convertNodeName(pod *corev1.Pod, converter *kosmosv1alpha1.NodeNameConverte
}
}

func converToleration(pod *corev1.Pod, conveter *kosmosv1alpha1.TolerationConverter) {
if conveter == nil {
func convertToleration(pod *corev1.Pod, converter *kosmosv1alpha1.TolerationConverter) {
if converter == nil {
return
}

switch conveter.ConvertType {
switch converter.ConvertType {
case kosmosv1alpha1.Add:
if pod.Spec.Tolerations == nil {
pod.Spec.Tolerations = conveter.Tolerations
pod.Spec.Tolerations = converter.Tolerations
}
case kosmosv1alpha1.Remove:
pod.Spec.Tolerations = nil
case kosmosv1alpha1.Replace:
pod.Spec.Tolerations = conveter.Tolerations
pod.Spec.Tolerations = converter.Tolerations
default:
klog.Warningf("Skip other convert type, Tolerations: %s", conveter.ConvertType)
klog.Warningf("Skip other convert type, Tolerations: %s", converter.ConvertType)
}
}

Expand Down
Loading