You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@uniffle.apache.org by GitBox <gi...@apache.org> on 2022/08/26 06:40:17 UTC

[GitHub] [incubator-uniffle] wangao1236 opened a new pull request, #188: [ISSUE-48][FEATURE][FOLLOW UP] Add webhook component

wangao1236 opened a new pull request, #188:
URL: https://github.com/apache/incubator-uniffle/pull/188

   <!--
   Thanks for sending a pull request!  Here are some tips for you:
     1. If this is your first time, please read our contributor guidelines: https://github.com/Tencent/Firestorm/blob/master/CONTRIBUTING.md
     2. Ensure you have added or run the appropriate tests for your PR
     3. If the PR is unfinished, add '[WIP]' in your PR title, e.g., '[WIP]XXXX Your PR title ...'.
     4. Be sure to keep the PR description updated to reflect all changes.
     5. Please write your PR title to summarize what this PR proposes.
     6. If possible, provide a concise example to reproduce the issue for a faster review.
   -->
   
   ### What changes were proposed in this pull request?
   for issue #48 
   I add webhook module this time, maybe some logic is missing unit test, I will add in the next PR.
   <!--
   Please clarify what changes you are proposing. The purpose of this section is to outline the changes and how this PR fixes the issue.
   If possible, please consider writing useful notes for better and faster reviews in your PR. See the examples below.
     1. If you refactor some codes with changing classes, showing the class hierarchy will help reviewers.
     2. If you fix some SQL features, you can provide some references of other DBMSes.
     3. If there is design documentation, please add the link.
     4. If there is a discussion in the mailing list, please add the link.
   -->
   
   
   ### Why are the changes needed?
   <!--
   Please clarify why the changes are needed. For instance,
     1. If you propose a new API, clarify the use case for a new API.
     2. If you fix a bug, you can clarify why it is a bug.
   -->
   
   
   ### Does this PR introduce _any_ user-facing change?
   <!--
   Note that it means *any* user-facing change including all aspects such as the documentation fix.
   If yes, please clarify the previous behavior and the change this PR proposes - provide the console output, description and/or an example to show the behavior difference if possible.
   If possible, please also clarify if this is a user-facing change compared to the released versions or within the unreleased branches such as master.
   If no, write 'No'.
   -->
   
   
   ### How was this patch tested?
   <!--
   If tests were added, say they were added here. Please make sure to add some test cases that check the changes thoroughly including negative and positive cases if possible.
   If it was tested in a way different from regular unit tests, please clarify how you tested step by step, ideally copy and paste-able, so that other reviewers can test and check, and descendants can verify in the future.
   If tests were not added, please describe why they were not added and/or why it was difficult to add.
   -->
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@uniffle.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@uniffle.apache.org
For additional commands, e-mail: issues-help@uniffle.apache.org


[GitHub] [incubator-uniffle] wangao1236 commented on a diff in pull request #188: [ISSUE-48][FEATURE][FOLLOW UP] Add webhook component

Posted by GitBox <gi...@apache.org>.
wangao1236 commented on code in PR #188:
URL: https://github.com/apache/incubator-uniffle/pull/188#discussion_r955828463


##########
deploy/kubernetes/operator/pkg/constants/constants.go:
##########
@@ -0,0 +1,60 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 constants
+
+const (
+	// LeaderIDSuffix is the suffix of leader id used for components' leader election
+	LeaderIDSuffix = "rss.tenant.io"

Review Comment:
   Sorry for ignoring it before, it has been modified



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@uniffle.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@uniffle.apache.org
For additional commands, e-mail: issues-help@uniffle.apache.org


[GitHub] [incubator-uniffle] jerqi commented on a diff in pull request #188: [ISSUE-48][FEATURE][FOLLOW UP] Add webhook component

Posted by GitBox <gi...@apache.org>.
jerqi commented on code in PR #188:
URL: https://github.com/apache/incubator-uniffle/pull/188#discussion_r955806535


##########
deploy/kubernetes/operator/pkg/constants/constants.go:
##########
@@ -0,0 +1,60 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 constants
+
+const (
+	// LeaderIDSuffix is the suffix of leader id used for components' leader election
+	LeaderIDSuffix = "rss.tenant.io"

Review Comment:
   `rss.tenant.io` -> `uniffle.apache.org`?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@uniffle.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@uniffle.apache.org
For additional commands, e-mail: issues-help@uniffle.apache.org


[GitHub] [incubator-uniffle] thousandhu commented on a diff in pull request #188: [ISSUE-48][FEATURE][FOLLOW UP] Add webhook component

Posted by GitBox <gi...@apache.org>.
thousandhu commented on code in PR #188:
URL: https://github.com/apache/incubator-uniffle/pull/188#discussion_r958149253


##########
deploy/kubernetes/operator/pkg/webhook/syncer/syncer.go:
##########
@@ -0,0 +1,249 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 syncer
+
+import (
+	"context"
+	"reflect"
+	"time"
+
+	"golang.org/x/sync/errgroup"
+	admissionv1 "k8s.io/api/admissionregistration/v1"
+	corev1 "k8s.io/api/core/v1"
+	"k8s.io/apimachinery/pkg/api/errors"
+	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
+	"k8s.io/client-go/kubernetes"
+	"k8s.io/klog/v2"
+	"k8s.io/utils/pointer"
+	"sigs.k8s.io/controller-runtime/pkg/manager"
+
+	unifflev1alpha1 "github.com/apache/incubator-uniffle/deploy/kubernetes/operator/api/uniffle/v1alpha1"
+	"github.com/apache/incubator-uniffle/deploy/kubernetes/operator/pkg/constants"
+	"github.com/apache/incubator-uniffle/deploy/kubernetes/operator/pkg/utils"
+	webhookconstants "github.com/apache/incubator-uniffle/deploy/kubernetes/operator/pkg/webhook/constants"
+)
+
+var _ ConfigSyncer = &configSyncer{}
+
+// ConfigSyncer syncs ValidatingWebhookConfigurations and MutatingWebhookConfigurations.
+type ConfigSyncer interface {
+	manager.Runnable
+}
+
+// NewConfigSyncer creates a ConfigSyncer.
+func NewConfigSyncer(caCert []byte, externalService string,
+	kubeClient kubernetes.Interface) ConfigSyncer {
+	return newConfigSyncer(caCert, externalService, kubeClient)
+}
+
+// newConfigSyncer creates a configSyncer.
+func newConfigSyncer(caCert []byte, externalService string,
+	kubeClient kubernetes.Interface) *configSyncer {
+	return &configSyncer{
+		caCert:          caCert,
+		externalService: externalService,
+		kubeClient:      kubeClient,
+	}
+}
+
+// configSyncer implements the ConfigSyncer interface.
+type configSyncer struct {
+	caCert          []byte
+	externalService string
+	kubeClient      kubernetes.Interface
+}
+
+// Start starts the ConfigSyncer.
+func (cs *configSyncer) Start(ctx context.Context) error {
+	klog.V(2).Info("config syncer started")
+	for {
+		select {
+		case <-ctx.Done():
+			klog.V(3).Info("stop syncing webhook configurations")
+			return nil
+		default:
+		}
+		if err := cs.syncWebhookCfg(); err != nil {
+			klog.Errorf("sync webhook configuration failed: %v", err)
+		}
+		time.Sleep(time.Minute)
+	}
+}
+
+// syncWebhookCfg synchronizes the validatingWebhookConfiguration and mutatingWebhookConfiguration objects.
+func (cs *configSyncer) syncWebhookCfg() error {
+	currentVWC, currentMWC := cs.generateWebhookCfg()
+	eg := errgroup.Group{}
+	eg.Go(func() error {
+		return cs.syncValidatingWebhookCfg(currentVWC)
+	})
+	eg.Go(func() error {
+		return cs.syncMutatingWebhookCfg(currentMWC)
+	})
+	return eg.Wait()
+}
+
+// syncValidatingWebhookCfg synchronizes the validatingWebhookConfiguration object.
+func (cs *configSyncer) syncValidatingWebhookCfg(
+	currentVWC *admissionv1.ValidatingWebhookConfiguration) error {
+	vwc, err := cs.kubeClient.AdmissionregistrationV1().ValidatingWebhookConfigurations().
+		Get(context.Background(), webhookconstants.ComponentName, metav1.GetOptions{})
+	if err != nil {
+		if errors.IsNotFound(err) {
+			_, err = cs.kubeClient.AdmissionregistrationV1().ValidatingWebhookConfigurations().
+				Create(context.Background(), currentVWC, metav1.CreateOptions{})
+		}
+		return err
+	}
+	if reflect.DeepEqual(vwc.Webhooks, currentVWC.Webhooks) {
+		return nil
+	}
+	vwc.Webhooks = currentVWC.Webhooks
+	_, err = cs.kubeClient.AdmissionregistrationV1().ValidatingWebhookConfigurations().
+		Update(context.Background(), vwc, metav1.UpdateOptions{})
+	return err
+}
+
+// syncMutatingWebhookCfg synchronizes the mutatingWebhookConfiguration object.
+func (cs *configSyncer) syncMutatingWebhookCfg(
+	currentMWC *admissionv1.MutatingWebhookConfiguration) error {
+	vwc, err := cs.kubeClient.AdmissionregistrationV1().MutatingWebhookConfigurations().
+		Get(context.Background(), webhookconstants.ComponentName, metav1.GetOptions{})
+	if err != nil {
+		if errors.IsNotFound(err) {
+			_, err = cs.kubeClient.AdmissionregistrationV1().MutatingWebhookConfigurations().
+				Create(context.Background(), currentMWC, metav1.CreateOptions{})
+		}
+		return err
+	}
+	if reflect.DeepEqual(vwc.Webhooks, currentMWC.Webhooks) {
+		return nil
+	}
+	vwc.Webhooks = currentMWC.Webhooks
+	_, err = cs.kubeClient.AdmissionregistrationV1().MutatingWebhookConfigurations().
+		Update(context.Background(), vwc, metav1.UpdateOptions{})
+	return err
+}
+
+// generateWebhookCfg generates the validatingWebhookConfiguration and mutatingWebhookConfiguration objects.
+func (cs *configSyncer) generateWebhookCfg() (

Review Comment:
   miss return type?



##########
deploy/kubernetes/operator/pkg/webhook/inspector/pod.go:
##########
@@ -0,0 +1,146 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 inspector
+
+import (
+	"context"
+	"encoding/json"
+	"fmt"
+	"strings"
+
+	admissionv1 "k8s.io/api/admission/v1"
+	corev1 "k8s.io/api/core/v1"
+	apierrors "k8s.io/apimachinery/pkg/api/errors"
+	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
+	"k8s.io/apimachinery/pkg/util/sets"
+	"k8s.io/klog/v2"
+
+	unifflev1alpha1 "github.com/apache/incubator-uniffle/deploy/kubernetes/operator/api/uniffle/v1alpha1"
+	"github.com/apache/incubator-uniffle/deploy/kubernetes/operator/pkg/utils"
+	"github.com/apache/incubator-uniffle/deploy/kubernetes/operator/pkg/webhook/util"
+)
+
+// validateDeletingShuffleServer validates the delete operation towards shuffle server pods,
+// and update exclude nodes in configMap.
+func (i *inspector) validateDeletingShuffleServer(ar *admissionv1.AdmissionReview) *admissionv1.AdmissionReview {
+	pod := &corev1.Pod{}
+	if err := json.Unmarshal(ar.Request.OldObject.Raw, pod); err != nil {
+		klog.Errorf("unmarshal object of AdmissionReview (%v) failed: %v",
+			string(ar.Request.Object.Raw), err)
+		return util.AdmissionReviewFailed(ar, err)
+	}
+	rssName := utils.GetRssNameByPod(pod)
+	// allow pods which are not shuffle servers or have been set deletion timestamp.
+	if rssName == "" || !util.NeedInspectPod(pod) {
+		klog.V(4).Infof("ignored non shuffle server or deleting pod: %v->(%+v/%+v/%v)",
+			utils.UniqueName(pod), pod.Labels, pod.Annotations, pod.DeletionTimestamp)
+		return util.AdmissionReviewAllow(ar)
+	}
+	klog.V(4).Infof("check shuffle server pod: %v", utils.BuildShuffleServerKey(pod))
+	rss, err := i.rssLister.RemoteShuffleServices(pod.Namespace).Get(rssName)
+	if err != nil {
+		if apierrors.IsNotFound(err) {
+			return util.AdmissionReviewAllow(ar)
+		}
+		return util.AdmissionReviewFailed(ar, err)
+	}
+	// we can only delete shuffle server pods when rss is in upgrading phase.
+	if rss.Status.Phase != unifflev1alpha1.RSSUpgrading && rss.Status.Phase != unifflev1alpha1.RSSTerminating {
+		message := fmt.Sprintf("can not delete the shuffle server pod (%v) directly",
+			utils.UniqueName(pod))
+		klog.V(4).Info(message)
+		return util.AdmissionReviewForbidden(ar, message)
+	}
+
+	// when the rss uses specific upgrade mode, we need to check whether the pod is specific.
+	if rss.Spec.ShuffleServer.UpgradeStrategy.Type == unifflev1alpha1.SpecificUpgrade {
+		specificNames := rss.Spec.ShuffleServer.UpgradeStrategy.SpecificNames
+		isSpecific := false
+		for _, name := range specificNames {
+			if name == pod.Name {
+				isSpecific = true
+				break
+			}
+		}
+		if !isSpecific {
+			message := fmt.Sprintf("can not delete the shuffle server pod (%v) which is not specific",
+				utils.UniqueName(pod))
+			klog.V(4).Info(message)
+			return util.AdmissionReviewForbidden(ar, message)
+		}
+	}
+
+	// update targetKeys field in status of rss and exclude nodes in configMap used by coordinators.
+	if err = i.updateTargetKeysAndExcludeNodes(rss, pod); err != nil {
+		return util.AdmissionReviewFailed(ar, err)
+	}
+
+	// check whether the shuffle server pod can be deleted.
+	if i.ignoreLastApps || util.HasZeroApps(pod) {
+		klog.V(3).Infof("shuffle server pod (%v) will be deleted", utils.BuildShuffleServerKey(pod))
+		return util.AdmissionReviewAllow(ar)
+	}
+	message := "can not delete the shuffle server: " + utils.GetShuffleServerNode(pod)

Review Comment:
   Should we add the reason such as "there are apps still running in the node" into message?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@uniffle.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@uniffle.apache.org
For additional commands, e-mail: issues-help@uniffle.apache.org


[GitHub] [incubator-uniffle] codecov-commenter commented on pull request #188: [ISSUE-48][FEATURE][FOLLOW UP] Add webhook component

Posted by GitBox <gi...@apache.org>.
codecov-commenter commented on PR #188:
URL: https://github.com/apache/incubator-uniffle/pull/188#issuecomment-1228133904

   # [Codecov](https://codecov.io/gh/apache/incubator-uniffle/pull/188?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) Report
   > Merging [#188](https://codecov.io/gh/apache/incubator-uniffle/pull/188?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (018c766) into [master](https://codecov.io/gh/apache/incubator-uniffle/commit/c25e5a1469a5a5f8e0fb5b2c7256862b1a6e2de7?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (c25e5a1) will **decrease** coverage by `1.37%`.
   > The diff coverage is `n/a`.
   
   ```diff
   @@             Coverage Diff              @@
   ##             master     #188      +/-   ##
   ============================================
   - Coverage     58.41%   57.03%   -1.38%     
   + Complexity     1271     1193      -78     
   ============================================
     Files           158      149       -9     
     Lines          8428     7930     -498     
     Branches        782      751      -31     
   ============================================
   - Hits           4923     4523     -400     
   + Misses         3253     3166      -87     
   + Partials        252      241      -11     
   ```
   
   
   | [Impacted Files](https://codecov.io/gh/apache/incubator-uniffle/pull/188?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) | Coverage Δ | |
   |---|---|---|
   | [.../apache/uniffle/coordinator/CoordinatorServer.java](https://codecov.io/gh/apache/incubator-uniffle/pull/188/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-Y29vcmRpbmF0b3Ivc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL3VuaWZmbGUvY29vcmRpbmF0b3IvQ29vcmRpbmF0b3JTZXJ2ZXIuamF2YQ==) | `60.21% <0.00%> (-5.38%)` | :arrow_down: |
   | [...pache/spark/shuffle/writer/WriteBufferManager.java](https://codecov.io/gh/apache/incubator-uniffle/pull/188/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-Y2xpZW50LXNwYXJrL2NvbW1vbi9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvc3Bhcmsvc2h1ZmZsZS93cml0ZXIvV3JpdGVCdWZmZXJNYW5hZ2VyLmphdmE=) | | |
   | [...org/apache/spark/shuffle/RssSparkShuffleUtils.java](https://codecov.io/gh/apache/incubator-uniffle/pull/188/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-Y2xpZW50LXNwYXJrL2NvbW1vbi9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvc3Bhcmsvc2h1ZmZsZS9Sc3NTcGFya1NodWZmbGVVdGlscy5qYXZh) | | |
   | [.../java/org/apache/spark/shuffle/RssSparkConfig.java](https://codecov.io/gh/apache/incubator-uniffle/pull/188/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-Y2xpZW50LXNwYXJrL2NvbW1vbi9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvc3Bhcmsvc2h1ZmZsZS9Sc3NTcGFya0NvbmZpZy5qYXZh) | | |
   | [...org/apache/spark/shuffle/writer/AddBlockEvent.java](https://codecov.io/gh/apache/incubator-uniffle/pull/188/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-Y2xpZW50LXNwYXJrL2NvbW1vbi9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvc3Bhcmsvc2h1ZmZsZS93cml0ZXIvQWRkQmxvY2tFdmVudC5qYXZh) | | |
   | [...k/shuffle/writer/WrappedByteArrayOutputStream.java](https://codecov.io/gh/apache/incubator-uniffle/pull/188/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-Y2xpZW50LXNwYXJrL2NvbW1vbi9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvc3Bhcmsvc2h1ZmZsZS93cml0ZXIvV3JhcHBlZEJ5dGVBcnJheU91dHB1dFN0cmVhbS5qYXZh) | | |
   | [.../org/apache/spark/shuffle/writer/WriterBuffer.java](https://codecov.io/gh/apache/incubator-uniffle/pull/188/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-Y2xpZW50LXNwYXJrL2NvbW1vbi9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvc3Bhcmsvc2h1ZmZsZS93cml0ZXIvV3JpdGVyQnVmZmVyLmphdmE=) | | |
   | [...che/spark/shuffle/writer/BufferManagerOptions.java](https://codecov.io/gh/apache/incubator-uniffle/pull/188/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-Y2xpZW50LXNwYXJrL2NvbW1vbi9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvc3Bhcmsvc2h1ZmZsZS93cml0ZXIvQnVmZmVyTWFuYWdlck9wdGlvbnMuamF2YQ==) | | |
   | [...ava/org/apache/spark/shuffle/RssShuffleHandle.java](https://codecov.io/gh/apache/incubator-uniffle/pull/188/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-Y2xpZW50LXNwYXJrL2NvbW1vbi9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvc3Bhcmsvc2h1ZmZsZS9Sc3NTaHVmZmxlSGFuZGxlLmphdmE=) | | |
   | [...e/spark/shuffle/reader/RssShuffleDataIterator.java](https://codecov.io/gh/apache/incubator-uniffle/pull/188/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-Y2xpZW50LXNwYXJrL2NvbW1vbi9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvc3Bhcmsvc2h1ZmZsZS9yZWFkZXIvUnNzU2h1ZmZsZURhdGFJdGVyYXRvci5qYXZh) | | |
   
   :mega: We’re building smart automated test selection to slash your CI/CD build times. [Learn more](https://about.codecov.io/iterative-testing/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@uniffle.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@uniffle.apache.org
For additional commands, e-mail: issues-help@uniffle.apache.org


[GitHub] [incubator-uniffle] wangao1236 commented on a diff in pull request #188: [ISSUE-48][FEATURE][FOLLOW UP] Add webhook component

Posted by GitBox <gi...@apache.org>.
wangao1236 commented on code in PR #188:
URL: https://github.com/apache/incubator-uniffle/pull/188#discussion_r958249926


##########
deploy/kubernetes/operator/pkg/webhook/inspector/pod.go:
##########
@@ -0,0 +1,146 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 inspector
+
+import (
+	"context"
+	"encoding/json"
+	"fmt"
+	"strings"
+
+	admissionv1 "k8s.io/api/admission/v1"
+	corev1 "k8s.io/api/core/v1"
+	apierrors "k8s.io/apimachinery/pkg/api/errors"
+	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
+	"k8s.io/apimachinery/pkg/util/sets"
+	"k8s.io/klog/v2"
+
+	unifflev1alpha1 "github.com/apache/incubator-uniffle/deploy/kubernetes/operator/api/uniffle/v1alpha1"
+	"github.com/apache/incubator-uniffle/deploy/kubernetes/operator/pkg/utils"
+	"github.com/apache/incubator-uniffle/deploy/kubernetes/operator/pkg/webhook/util"
+)
+
+// validateDeletingShuffleServer validates the delete operation towards shuffle server pods,
+// and update exclude nodes in configMap.
+func (i *inspector) validateDeletingShuffleServer(ar *admissionv1.AdmissionReview) *admissionv1.AdmissionReview {
+	pod := &corev1.Pod{}
+	if err := json.Unmarshal(ar.Request.OldObject.Raw, pod); err != nil {
+		klog.Errorf("unmarshal object of AdmissionReview (%v) failed: %v",
+			string(ar.Request.Object.Raw), err)
+		return util.AdmissionReviewFailed(ar, err)
+	}
+	rssName := utils.GetRssNameByPod(pod)
+	// allow pods which are not shuffle servers or have been set deletion timestamp.
+	if rssName == "" || !util.NeedInspectPod(pod) {
+		klog.V(4).Infof("ignored non shuffle server or deleting pod: %v->(%+v/%+v/%v)",
+			utils.UniqueName(pod), pod.Labels, pod.Annotations, pod.DeletionTimestamp)
+		return util.AdmissionReviewAllow(ar)
+	}
+	klog.V(4).Infof("check shuffle server pod: %v", utils.BuildShuffleServerKey(pod))
+	rss, err := i.rssLister.RemoteShuffleServices(pod.Namespace).Get(rssName)
+	if err != nil {
+		if apierrors.IsNotFound(err) {
+			return util.AdmissionReviewAllow(ar)
+		}
+		return util.AdmissionReviewFailed(ar, err)
+	}
+	// we can only delete shuffle server pods when rss is in upgrading phase.
+	if rss.Status.Phase != unifflev1alpha1.RSSUpgrading && rss.Status.Phase != unifflev1alpha1.RSSTerminating {
+		message := fmt.Sprintf("can not delete the shuffle server pod (%v) directly",
+			utils.UniqueName(pod))
+		klog.V(4).Info(message)
+		return util.AdmissionReviewForbidden(ar, message)
+	}
+
+	// when the rss uses specific upgrade mode, we need to check whether the pod is specific.
+	if rss.Spec.ShuffleServer.UpgradeStrategy.Type == unifflev1alpha1.SpecificUpgrade {
+		specificNames := rss.Spec.ShuffleServer.UpgradeStrategy.SpecificNames
+		isSpecific := false
+		for _, name := range specificNames {
+			if name == pod.Name {
+				isSpecific = true
+				break
+			}
+		}
+		if !isSpecific {
+			message := fmt.Sprintf("can not delete the shuffle server pod (%v) which is not specific",
+				utils.UniqueName(pod))
+			klog.V(4).Info(message)
+			return util.AdmissionReviewForbidden(ar, message)
+		}
+	}
+
+	// update targetKeys field in status of rss and exclude nodes in configMap used by coordinators.
+	if err = i.updateTargetKeysAndExcludeNodes(rss, pod); err != nil {
+		return util.AdmissionReviewFailed(ar, err)
+	}
+
+	// check whether the shuffle server pod can be deleted.
+	if i.ignoreLastApps || util.HasZeroApps(pod) {
+		klog.V(3).Infof("shuffle server pod (%v) will be deleted", utils.BuildShuffleServerKey(pod))
+		return util.AdmissionReviewAllow(ar)
+	}
+	message := "can not delete the shuffle server: " + utils.GetShuffleServerNode(pod)

Review Comment:
   Sounds good, I have modified.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@uniffle.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@uniffle.apache.org
For additional commands, e-mail: issues-help@uniffle.apache.org


[GitHub] [incubator-uniffle] thousandhu commented on a diff in pull request #188: [ISSUE-48][FEATURE][FOLLOW UP] Add webhook component

Posted by GitBox <gi...@apache.org>.
thousandhu commented on code in PR #188:
URL: https://github.com/apache/incubator-uniffle/pull/188#discussion_r958149253


##########
deploy/kubernetes/operator/pkg/webhook/syncer/syncer.go:
##########
@@ -0,0 +1,249 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 syncer
+
+import (
+	"context"
+	"reflect"
+	"time"
+
+	"golang.org/x/sync/errgroup"
+	admissionv1 "k8s.io/api/admissionregistration/v1"
+	corev1 "k8s.io/api/core/v1"
+	"k8s.io/apimachinery/pkg/api/errors"
+	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
+	"k8s.io/client-go/kubernetes"
+	"k8s.io/klog/v2"
+	"k8s.io/utils/pointer"
+	"sigs.k8s.io/controller-runtime/pkg/manager"
+
+	unifflev1alpha1 "github.com/apache/incubator-uniffle/deploy/kubernetes/operator/api/uniffle/v1alpha1"
+	"github.com/apache/incubator-uniffle/deploy/kubernetes/operator/pkg/constants"
+	"github.com/apache/incubator-uniffle/deploy/kubernetes/operator/pkg/utils"
+	webhookconstants "github.com/apache/incubator-uniffle/deploy/kubernetes/operator/pkg/webhook/constants"
+)
+
+var _ ConfigSyncer = &configSyncer{}
+
+// ConfigSyncer syncs ValidatingWebhookConfigurations and MutatingWebhookConfigurations.
+type ConfigSyncer interface {
+	manager.Runnable
+}
+
+// NewConfigSyncer creates a ConfigSyncer.
+func NewConfigSyncer(caCert []byte, externalService string,
+	kubeClient kubernetes.Interface) ConfigSyncer {
+	return newConfigSyncer(caCert, externalService, kubeClient)
+}
+
+// newConfigSyncer creates a configSyncer.
+func newConfigSyncer(caCert []byte, externalService string,
+	kubeClient kubernetes.Interface) *configSyncer {
+	return &configSyncer{
+		caCert:          caCert,
+		externalService: externalService,
+		kubeClient:      kubeClient,
+	}
+}
+
+// configSyncer implements the ConfigSyncer interface.
+type configSyncer struct {
+	caCert          []byte
+	externalService string
+	kubeClient      kubernetes.Interface
+}
+
+// Start starts the ConfigSyncer.
+func (cs *configSyncer) Start(ctx context.Context) error {
+	klog.V(2).Info("config syncer started")
+	for {
+		select {
+		case <-ctx.Done():
+			klog.V(3).Info("stop syncing webhook configurations")
+			return nil
+		default:
+		}
+		if err := cs.syncWebhookCfg(); err != nil {
+			klog.Errorf("sync webhook configuration failed: %v", err)
+		}
+		time.Sleep(time.Minute)
+	}
+}
+
+// syncWebhookCfg synchronizes the validatingWebhookConfiguration and mutatingWebhookConfiguration objects.
+func (cs *configSyncer) syncWebhookCfg() error {
+	currentVWC, currentMWC := cs.generateWebhookCfg()
+	eg := errgroup.Group{}
+	eg.Go(func() error {
+		return cs.syncValidatingWebhookCfg(currentVWC)
+	})
+	eg.Go(func() error {
+		return cs.syncMutatingWebhookCfg(currentMWC)
+	})
+	return eg.Wait()
+}
+
+// syncValidatingWebhookCfg synchronizes the validatingWebhookConfiguration object.
+func (cs *configSyncer) syncValidatingWebhookCfg(
+	currentVWC *admissionv1.ValidatingWebhookConfiguration) error {
+	vwc, err := cs.kubeClient.AdmissionregistrationV1().ValidatingWebhookConfigurations().
+		Get(context.Background(), webhookconstants.ComponentName, metav1.GetOptions{})
+	if err != nil {
+		if errors.IsNotFound(err) {
+			_, err = cs.kubeClient.AdmissionregistrationV1().ValidatingWebhookConfigurations().
+				Create(context.Background(), currentVWC, metav1.CreateOptions{})
+		}
+		return err
+	}
+	if reflect.DeepEqual(vwc.Webhooks, currentVWC.Webhooks) {
+		return nil
+	}
+	vwc.Webhooks = currentVWC.Webhooks
+	_, err = cs.kubeClient.AdmissionregistrationV1().ValidatingWebhookConfigurations().
+		Update(context.Background(), vwc, metav1.UpdateOptions{})
+	return err
+}
+
+// syncMutatingWebhookCfg synchronizes the mutatingWebhookConfiguration object.
+func (cs *configSyncer) syncMutatingWebhookCfg(
+	currentMWC *admissionv1.MutatingWebhookConfiguration) error {
+	vwc, err := cs.kubeClient.AdmissionregistrationV1().MutatingWebhookConfigurations().
+		Get(context.Background(), webhookconstants.ComponentName, metav1.GetOptions{})
+	if err != nil {
+		if errors.IsNotFound(err) {
+			_, err = cs.kubeClient.AdmissionregistrationV1().MutatingWebhookConfigurations().
+				Create(context.Background(), currentMWC, metav1.CreateOptions{})
+		}
+		return err
+	}
+	if reflect.DeepEqual(vwc.Webhooks, currentMWC.Webhooks) {
+		return nil
+	}
+	vwc.Webhooks = currentMWC.Webhooks
+	_, err = cs.kubeClient.AdmissionregistrationV1().MutatingWebhookConfigurations().
+		Update(context.Background(), vwc, metav1.UpdateOptions{})
+	return err
+}
+
+// generateWebhookCfg generates the validatingWebhookConfiguration and mutatingWebhookConfiguration objects.
+func (cs *configSyncer) generateWebhookCfg() (

Review Comment:
   miss return type?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@uniffle.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@uniffle.apache.org
For additional commands, e-mail: issues-help@uniffle.apache.org


[GitHub] [incubator-uniffle] jerqi merged pull request #188: [ISSUE-48][FEATURE][FOLLOW UP] Add webhook component

Posted by GitBox <gi...@apache.org>.
jerqi merged PR #188:
URL: https://github.com/apache/incubator-uniffle/pull/188


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@uniffle.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@uniffle.apache.org
For additional commands, e-mail: issues-help@uniffle.apache.org


[GitHub] [incubator-uniffle] jerqi commented on pull request #188: [ISSUE-48][FEATURE][FOLLOW UP] Add webhook component

Posted by GitBox <gi...@apache.org>.
jerqi commented on PR #188:
URL: https://github.com/apache/incubator-uniffle/pull/188#issuecomment-1228126759

   @zuston @thousandhu @czy006 Could you help me review this patch?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@uniffle.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@uniffle.apache.org
For additional commands, e-mail: issues-help@uniffle.apache.org


[GitHub] [incubator-uniffle] thousandhu commented on pull request #188: [ISSUE-48][FEATURE][FOLLOW UP] Add webhook component

Posted by GitBox <gi...@apache.org>.
thousandhu commented on PR #188:
URL: https://github.com/apache/incubator-uniffle/pull/188#issuecomment-1233662024

   LGTM, +1


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@uniffle.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@uniffle.apache.org
For additional commands, e-mail: issues-help@uniffle.apache.org