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

Feat:Add Gateway Plugin Support #686

Merged
merged 10 commits into from
Sep 18, 2024
Merged

Feat:Add Gateway Plugin Support #686

merged 10 commits into from
Sep 18, 2024

Conversation

Gidi233
Copy link
Contributor

@Gidi233 Gidi233 commented Sep 2, 2024

What type of PR is this?
/kind api-change
/kind feature

What this PR does / why we need it:
Users can choose kuma and nginx in the configuration of rollout and fleet flagger.
Specifically, you can set the chart and value of the helm deployment gateway in the fleet configuration.
You can specify the host of Ingress (required) and the protocol used by Kuma (default is http) in the rollout configuration.
Ingress can automatically complete the deployment of canary through application.
Kuma needs to manually install Prometheus and mesh in the target cluster.

Which issue(s) this PR fixes:
Fixes #651

Does this PR introduce a user-facing change?:
For application:

    ......
      rollout:
        trafficRoutingProvider: nginx
        rolloutPolicy:
          trafficRouting:
            ......
            host: "app.example.com"
---
    ......
      rollout:
        trafficRoutingProvider: kuma
        rolloutPolicy:
          trafficRouting:
            ......
            protocol: http

For Fleet

  ......
  plugin:
    flagger:
      trafficRoutingProvider: nginx
      config:
        chart: 
        extraArgs: 

Copy link

netlify bot commented Sep 2, 2024

Deploy Preview for kurator-dev canceled.

Name Link
🔨 Latest commit 7a5c768
🔍 Latest deploy log https://app.netlify.com/sites/kurator-dev/deploys/66e39441602b280008b783d2

Copy link
Contributor

@LiZhenCheng9527 LiZhenCheng9527 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your PR is too large.
In fact, it can be split into multiple PRs such as API changes, fleet plugin installation implementation, feature implementation, etc.
It is convenient for development and review.

checkIntervalSeconds: 90
checkFailedTimes: 2
metrics:
- name: my-metric
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The name my-metric is not accurate enough, so we suggest changing it to nginx-request-success-rate.

checkIntervalSeconds: 90
checkFailedTimes: 2
metrics:
- name: my-metric
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

checkIntervalSeconds: 90
checkFailedTimes: 2
metrics:
- name: my-metric
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

// number: application.syncPolicies.rollout.port
// ```
// +optional
Host string `json:"host,omitempty"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your comments are confusing, what should I put in this field? Is it ingress.name?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean, you only need to fill in the host field as the host of the ingress. The other default items will be hard-coded in the code as configured above.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So the contents of this field are the contents of spec.rules.host in the above?

// for kuma
// Defaults to http
// +optional
Protocol string `json:"protocol,omitempty"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this field only used by kuma?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes

// PublicTestloader defines whether to install the publictestloader or not.
// In addition to the public testloader you can configure here,
// you can also specify a private testloader in the Application.Spec.SyncPolicies.Rollout.TestLoader
PublicTestloader bool `json:"publicTestloader,omitempty"`
// ProviderConfig defines the configuration for the TrafficRoutingProvider.
// +optional
ProviderConfig *Config `json:"config,omitempty"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What can this field be configured for? Is it used to install TrafficRoutingProvider?
Please clarify in the comments

if err != nil {
return ctrl.Result{}, errors.Wrapf(err, "failed to set namespace %s istio-injection enable", rolloutPolicy.Workload.Namespace)
return ctrl.Result{}, errors.Wrapf(err, "failed to set namespace %s %s's Inject enable", rolloutPolicy.Workload.Namespace, provider)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return ctrl.Result{}, errors.Wrapf(err, "failed to set namespace %s %s's Inject enable", rolloutPolicy.Workload.Namespace, provider)
return ctrl.Result{}, errors.Wrapf(err, "failed to set namespace %s %s's sidecar inject enable", rolloutPolicy.Workload.Namespace, provider)

default:
return ctrl.Result{}, errors.Errorf("unknown provider type %s", provider)
}
log.Info("pre-operation of operating canary success")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove

@@ -270,6 +307,14 @@ func (a *ApplicationManager) deleteResourcesInMemberClusters(ctx context.Context
}
for _, cluster := range destinationClusters {
newClient := cluster.Client.CtrlRuntimeClient()

ns := &corev1.Namespace{}
if err := deleteResourceCreatedByKurator(ctx, namespacedName, newClient, ns); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why delete ns? Are you sure all the resources in this ns were created by Kurator?

@@ -569,6 +710,23 @@ func addLabels(obj client.Object, key, value string) client.Object {
return obj
}

func addAnnotations(obj client.Object, keysAndValues ...string) client.Object {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not use map to store keysAndValues?

// number: application.syncPolicies.rollout.port
// ```
// +optional
Host string `json:"host,omitempty"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So the contents of this field are the contents of spec.rules.host in the above?

@@ -239,6 +239,42 @@ type TrafficRoutingConfig struct {
// +optional
CorsPolicy *istiov1alpha3.CorsPolicy `json:"corsPolicy,omitempty"`

// Host defines the domain name you specify.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is `Host: spec.rules.host' ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes.

labels := ingress.GetLabels()
if set := sets.New(strings.Split(labels[ingressLabelKey], ",")...); set.Contains(rollout.ServiceName) {
if set.Len() == 1 {
if deleteErr := kubeClient.Delete(ctx, ingress); deleteErr != nil && !apierrors.IsNotFound(deleteErr) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you need to judge a NotFound Error here? There a branch ingress already in the cluster.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I'll delete it.

if set := sets.New(strings.Split(labels[ingressLabelKey], ",")...); set.Contains(rollout.ServiceName) {
if set.Len() == 1 {
if deleteErr := kubeClient.Delete(ctx, ingress); deleteErr != nil && !apierrors.IsNotFound(deleteErr) {
return errors.Wrapf(deleteErr, "failed to Delete ingress %s in %s", namespaceName.Name, namespaceName.Namespace)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit:

Suggested change
return errors.Wrapf(deleteErr, "failed to Delete ingress %s in %s", namespaceName.Name, namespaceName.Namespace)
return errors.Wrapf(deleteErr, "failed to Delete ingress %s in %s", rollout.Workload.Namespace, ingress.Name)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rollout.Workload.Namespace is the same as namespaceName.Name and I thought when an error occurs the ingress object will be null?
So I don't think it needs to be changed

labels[ingressLabelKey] = strings.Join(set.Delete(rollout.ServiceName).UnsortedList(), ",")
ingress.SetLabels(labels)
if err := kubeClient.Update(ctx, ingress); err != nil {
return errors.Wrapf(err, "failed to Update ingress %s in %s", namespaceName.Name, namespaceName.Namespace)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

ingress.Spec.Rules = newRules
labels[ingressLabelKey] = strings.Join(set.Delete(rollout.ServiceName).UnsortedList(), ",")
ingress.SetLabels(labels)
if err := kubeClient.Update(ctx, ingress); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why put update and delete in one function?
Separate these two functions

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

}

// create/update ingress configuration
func renderIngress(ingress *ingressv1.Ingress, rollout *applicationapi.RolloutConfig) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this only used by nginx?
Maybe the function name can be replaced to renderNginxIngress

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

obj.SetAnnotations(ann)
} else {
for k, v := range ann {
annotations[k] = v
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This may change the original annotations, which need to be evaluated to see if there is any .

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

checked

@LiZhenCheng9527
Copy link
Contributor

almost LGTM

Signed-off-by: Gidi233 <[email protected]>
@LiZhenCheng9527
Copy link
Contributor

/lgtm

Signed-off-by: Gidi233 <[email protected]>
@LiZhenCheng9527
Copy link
Contributor

Please fix lint error

@LiZhenCheng9527
Copy link
Contributor

/cc @hzxuzhonghu This pr is ready to merge

@kurator-bot
Copy link
Collaborator

@LiZhenCheng9527: GitHub didn't allow me to request PR reviews from the following users: is, ready, to, merge, This, pr.

Note that only kurator-dev members and repo collaborators can review this PR, and authors cannot review their own PRs.

In response to this:

/cc @hzxuzhonghu This pr is ready to merge

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

Copy link
Member

@hzxuzhonghu hzxuzhonghu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks

@kurator-bot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: hzxuzhonghu

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@hzxuzhonghu
Copy link
Member

/lgtm

@kurator-bot kurator-bot merged commit edd2ba6 into kurator-dev:main Sep 18, 2024
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add Gateway Plugin Support
4 participants