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

issue-522,implementation for OpenSearch Egress Rules lifecycle on APIv2 #527

Conversation

OleksiienkoMykyta
Copy link
Collaborator

@OleksiienkoMykyta OleksiienkoMykyta force-pushed the issue-522-implementation-for-OpenSearch-Egress-Rules-lifecycle-workflow-on-APIv2 branch 4 times, most recently from 93f3c74 to bde9855 Compare August 22, 2023 15:43
@OleksiienkoMykyta OleksiienkoMykyta changed the title issue-522,implementation for OpenSearch Egress Rules lifecycle on APIv2 [WIP]issue-522,implementation for OpenSearch Egress Rules lifecycle on APIv2 Aug 23, 2023
@OleksiienkoMykyta OleksiienkoMykyta force-pushed the issue-522-implementation-for-OpenSearch-Egress-Rules-lifecycle-workflow-on-APIv2 branch from bde9855 to 64565f5 Compare August 30, 2023 10:02
@OleksiienkoMykyta OleksiienkoMykyta changed the title [WIP]issue-522,implementation for OpenSearch Egress Rules lifecycle on APIv2 issue-522,implementation for OpenSearch Egress Rules lifecycle on APIv2 Aug 30, 2023
@OleksiienkoMykyta OleksiienkoMykyta force-pushed the issue-522-implementation-for-OpenSearch-Egress-Rules-lifecycle-workflow-on-APIv2 branch from 64565f5 to 8d82646 Compare August 30, 2023 10:12
Makefile Outdated
@@ -98,7 +98,7 @@ run: manifests generate fmt vet ## Run a controller from your host.
go run ./main.go

.PHONY: docker-build
docker-build: manifests generate test ## Build docker image with the manager.
docker-build: manifests generate ## test ## Build docker image with the manager.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please uncomment the test instruction

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

fixed

opensearchegressruleslog.Info("validate create", "name", r.Name)

if r.Spec.ClusterID == "" || r.Spec.OpenSearchBindingID == "" || r.Spec.Source == "" {
return fmt.Errorf("spec.ClusterID, spec.OpenSearchBindingId, spec.Source must be filled")
Copy link
Collaborator

Choose a reason for hiding this comment

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

In your yaml manifest fields are written in camelCase.

Suggested change
return fmt.Errorf("spec.ClusterID, spec.OpenSearchBindingId, spec.Source must be filled")
return fmt.Errorf("spec.ClusterId, spec.ppenSearchBindingId, spec.source must be filled")

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

fixed

Name string `json:"name"`
OpenSearchBindingID string `json:"openSearchBindingId"`
Source string `json:"source"`
Type string `json:"type"`
Copy link
Collaborator

Choose a reason for hiding this comment

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

API doc says that Type is not required. Please add ,omitempty tag.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

fixed

Comment on lines 58 to 60
func (er *OpenSearchEgressRules) GetJobID(jobName string) string {
return client.ObjectKeyFromObject(er).String() + "/" + jobName
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please remove the unused func

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

fixed

Comment on lines 55 to 56
OpenSearchEgressRulesEndpoint = "/cluster-management/v2/resources/applications/opensearch/egress-rules/v2"
OpenSearchEgressRuleDeleteEndpoint = "/cluster-management/v2/resources/applications/opensearch/egress-rules/v2/"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Both constants are identical. Please delete the second one.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

fixed

Comment on lines 41 to 48
var (
cfg *rest.Config
k8sClient client.Client
testEnv *envtest.Environment
ctx context.Context
cancel context.CancelFunc
MockInstAPI = mock.NewInstAPI()
)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please revert these changes of suit_test.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

fixed

Copy link
Collaborator

Choose a reason for hiding this comment

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

It seems you don't. Please revert these changes.

@OleksiienkoMykyta OleksiienkoMykyta force-pushed the issue-522-implementation-for-OpenSearch-Egress-Rules-lifecycle-workflow-on-APIv2 branch from 8d82646 to 6aec1e1 Compare August 30, 2023 12:20
@OleksiienkoMykyta OleksiienkoMykyta force-pushed the issue-522-implementation-for-OpenSearch-Egress-Rules-lifecycle-workflow-on-APIv2 branch from 6aec1e1 to 641c1cb Compare August 30, 2023 12:23

type OpenSearchEgressRulesSpec struct {
ClusterID string `json:"clusterId"`
Name string `json:"name"`
Copy link
Collaborator

Choose a reason for hiding this comment

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

As Instaclustr API doc says the field name should be returned by the API if you add a new egress rule, but this is not part of a creation request. You should move this field from the resource spec to its status

Copy link
Collaborator

Choose a reason for hiding this comment

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

I've looked at the request sample in the doc, and the name field` is passed there. I think you should test what if you don't pass it. If any error is returned then change nothing

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It`s described in spec file, and in request body, in general this field does not affect nothing, but I think we should implement code according to spec

Copy link
Contributor

Choose a reason for hiding this comment

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

please remove the name field from the spec, it's a read-only property.


type OpenSearchEgressRulesStatus struct {
ID string `json:"id,omitempty"`
Status string `json:"status,omitempty"`
Copy link
Collaborator

Choose a reason for hiding this comment

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

This field is never used. Please delete it

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

fixed

Comment on lines 41 to 48
var (
cfg *rest.Config
k8sClient client.Client
testEnv *envtest.Environment
ctx context.Context
cancel context.CancelFunc
MockInstAPI = mock.NewInstAPI()
)
Copy link
Collaborator

Choose a reason for hiding this comment

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

It seems you don't. Please revert these changes.

@OleksiienkoMykyta OleksiienkoMykyta force-pushed the issue-522-implementation-for-OpenSearch-Egress-Rules-lifecycle-workflow-on-APIv2 branch from 641c1cb to fadba6d Compare August 31, 2023 11:46
@OleksiienkoMykyta OleksiienkoMykyta force-pushed the issue-522-implementation-for-OpenSearch-Egress-Rules-lifecycle-workflow-on-APIv2 branch from fadba6d to b68c49e Compare August 31, 2023 11:59
@OleksiienkoMykyta OleksiienkoMykyta force-pushed the issue-522-implementation-for-OpenSearch-Egress-Rules-lifecycle-workflow-on-APIv2 branch from b68c49e to d60d68f Compare August 31, 2023 12:06
Comment on lines 50 to 55
if r.Spec.ClusterID == "" || r.Spec.OpenSearchBindingID == "" || r.Spec.Source == "" {
return fmt.Errorf("clusterId, openSearchBindingId, source must be filled")
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's remove this code. All these fields are already marked as required in the resource spec

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

fixed

Comment on lines 20 to 35
"context"
"encoding/json"
"errors"
"fmt"

"github.com/go-logr/logr"
"github.com/instaclustr/operator/pkg/instaclustr"
"github.com/instaclustr/operator/pkg/models"
"github.com/instaclustr/operator/pkg/scheduler"

k8serrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/types"
"k8s.io/client-go/tools/record"
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"

"k8s.io/apimachinery/pkg/runtime"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/log"

clusterresourcesv1beta1 "github.com/instaclustr/operator/apis/clusterresources/v1beta1"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Sort imports please

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

fixed

Comment on lines 118 to 119
err = json.Unmarshal(b, &rule.Status)
if err != nil {
l.Error(err, "failed to parse OpenSearch Egress Rule resource response from Instaclustr")
r.EventRecorder.Eventf(rule, models.Warning, models.ConvertionFailed,
"Failed to parse OpenSearch Egress Rule response from Instaclustr. Reason: %v", err,
)

return err
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's move unmarshal logic inside the client method

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

fixed

Comment on lines 128 to 129
// This hack was added because instaclustr api returns null value egress rule id, but it should be equal to pattern {clusterId}~{source}~{bindingId}
// This code could be removed after instaclustr fix bugs, to make code cleaner
Copy link
Collaborator

Choose a reason for hiding this comment

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

// This hack was added because the Instaclustr API returns an egress rule id with a null value, but it should be equal to the pattern {clusterId}{source}{bindingId}
// This code could be removed after the Instaclustr API team fixes this bug

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

fixed

Comment on lines 47 to 55
func (r *OpenSearchEgressRules) ValidateCreate() error {
opensearchegressruleslog.Info("validate create", "name", r.Name)

if r.Spec.ClusterID == "" || r.Spec.OpenSearchBindingID == "" || r.Spec.Source == "" {
return fmt.Errorf("clusterId, openSearchBindingId, source must be filled")
}
Copy link
Contributor

Choose a reason for hiding this comment

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

You also need to add enum validation for source: "ALERTING", "NOTIFICATIONS"
And for type: "SLACK", "WEBHOOK", "CUSTOM_WEBHOOK", "CHIME"

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think its unnecessary, all such validations implemented on Instaclustr API, and in case they add new types, logic wouldn't work. About "ALERTING" its already deprecated, I`d rather avoid such validations if it's possible

Copy link
Contributor

@DoodgeMatvey DoodgeMatvey Sep 1, 2023

Choose a reason for hiding this comment

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

Yea, but in such way it will be created in k8s but wasn't created in Instaclustr because of error.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

fixed

// log is for logging in this package.
var opensearchegressruleslog = logf.Log.WithName("opensearchegressrules-resource")

var openSearchBindingIDPattern, _ = regexp.Compile(`[\w-]+`)
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add this regular expression to constants

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Its only one usage, and its very specific regular expression, I don`t think that it is necessary

Copy link
Contributor

Choose a reason for hiding this comment

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

Such code should not be hardcoded like this, such constant expressions should be in constants I think

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

fixed

Comment on lines 50 to 55
if r.Spec.ClusterID == "" || r.Spec.OpenSearchBindingID == "" || r.Spec.Source == "" {
return fmt.Errorf("clusterId, openSearchBindingId, source must be filled")
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's strict to our error naming pattern, so please start it with cannot create OpenSearch Egress Rule

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

As Danylo sad, this validation is redundant, so I just removed it.
"Let's remove this code. All these fields are already marked as required in the resource spec"

Comment on lines +62 to +86
func (r *OpenSearchEgressRules) ValidateUpdate(old runtime.Object) error {
opensearchegressruleslog.Info("validate update", "name", r.Name)

oldRules := old.(*OpenSearchEgressRules)

if r.Status.ID == "" {
return r.ValidateCreate()
}

if r.Spec != oldRules.Spec {
return models.ErrImmutableSpec
}

return nil
}
Copy link
Contributor

Choose a reason for hiding this comment

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

If I am not wrong there are no API calls to update this entity.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

But there are no API calls to update entity, only creation when resource has wrong configuration, to avoid additional operations, like deletion and creation new one, we just can edit resorce and apply it.

Copy link
Contributor

Choose a reason for hiding this comment

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

How we will update resouce and apply it if there are no such API calls? How we will update it on instaclustr side? In such way you sad k8s will be updated but instaclustr part won't be updated

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

ok

Copy link
Collaborator

Choose a reason for hiding this comment

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

We need to decline the update of this resource. Without validation, if the customer tries to update this entity inside K8s and this action is passed successfully, it can be really confusing if the entity will not be updated on the Instaclustr API, but updated inside K8s

return models.ReconcileRequeue, err
}

// Handle resource deletion
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add TODO for such kind of comments that will be implemented in future

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Its not TODO, its just decription to operations, changed it on "It`s handling resource deletion", to add more context

@OleksiienkoMykyta OleksiienkoMykyta force-pushed the issue-522-implementation-for-OpenSearch-Egress-Rules-lifecycle-workflow-on-APIv2 branch 2 times, most recently from bbbc429 to 6732f3b Compare September 4, 2023 15:46
@OleksiienkoMykyta OleksiienkoMykyta force-pushed the issue-522-implementation-for-OpenSearch-Egress-Rules-lifecycle-workflow-on-APIv2 branch from 6732f3b to 5ed815b Compare September 4, 2023 15:48

type OpenSearchEgressRulesSpec struct {
ClusterID string `json:"clusterId"`
Name string `json:"name"`
Copy link
Contributor

Choose a reason for hiding this comment

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

please remove the name field from the spec, it's a read-only property.

Comment on lines 115 to 132
// This hack was added because the Instaclustr API returns an egress rule id with a null value, but it should be equal to the pattern {clusterId}~{source}~{bindingId}
// This code could be removed after the Instaclustr API team fixes this bug
if rule.Status.ID == "" {
rule.Status.ID = fmt.Sprintf("%s~%s~%s", rule.Spec.ClusterID, rule.Spec.Source, rule.Spec.OpenSearchBindingID)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Comment on lines 36 to 37
var theType = []string{"SLACK", "WEBHOOK", "CUSTOM_WEBHOOK", "CHIME"}
var source = []string{"NOTIFICATIONS"}
Copy link
Contributor

@ribaraka ribaraka Sep 5, 2023

Choose a reason for hiding this comment

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

theType -> destinationTypes
source -> sourcePlugins
and please add "ALERTING" to the sourcePlugins

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

fixed

Comment on lines 52 to 58
equalsToReg, _ := regexp.MatchString(models.OpenSearchBindingIDPattern, r.Spec.OpenSearchBindingID)

if !slices.Contains(source, r.Spec.Source) || !slices.Contains(theType, r.Spec.Type) {
return fmt.Errorf("the source should be equeal to one of options: %q , got: %q. the type should be equeal to one of options: %q , got: %q", source, theType, r.Spec.Source, r.Spec.Type)
}

if !equalsToReg {
return fmt.Errorf("mismatching openSearchBindingId to pattern: %s", models.OpenSearchBindingIDPattern)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

please move if !equalsToReg { immediately after the equalsToReg variable is assigned. And add an error

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

fixed

Comment on lines 151 to 154
err := r.API.DeleteOpenSearchEgressRule(rule.Status.ID)
if err != nil {
logger.Error(err, "failed to delete OpenSearch Egress Rule on Instaclustr")
Copy link
Contributor

@ribaraka ribaraka Sep 5, 2023

Choose a reason for hiding this comment

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

I think it's better to handle the NotFound error

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

fixed

Comment on lines +2317 to +2350
err = json.Unmarshal(b, &rule.Status)
if err != nil {
return err
}
Copy link
Contributor

Choose a reason for hiding this comment

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

It would be clearer if you just returned the bytes and only then converted them to rule.Status. This shows that the status is indeed changing and you are performing the patch operation.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

After discussion with the team, we agreed that we should convert data in client

@@ -98,6 +98,8 @@ type API interface {
ListAppVersions(app string) ([]*models.AppVersions, error)
GetDefaultCredentialsV1(clusterID string) (string, string, error)
UpdateClusterSettings(clusterID string, settings *models.ClusterSettings) error
CreateOpenSearchEgressRules(rule *clusterresourcesv1beta1.OpenSearchEgressRules) error
DeleteOpenSearchEgressRule(egressRuleId string) error
Copy link
Contributor

Choose a reason for hiding this comment

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

egressRuleId -> ID

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

fixed

@@ -62,4 +62,5 @@ var (
ErrPrivateLinkOnlyWithPrivateNetworkCluster = errors.New("private link is available only for private network clusters")
ErrPrivateLinkSupportedOnlyForSingleDC = errors.New("private link is only supported for a single data centre")
ErrPrivateLinkSupportedOnlyForAWS = errors.New("private link is supported only for an AWS cloud provider")
ErrImmutableSpec = errors.New("spec is immutable")
Copy link
Contributor

Choose a reason for hiding this comment

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

resource specification is immutable

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

fixed

@testisnullus testisnullus added the enhancement New feature or request label Sep 13, 2023
@OleksiienkoMykyta OleksiienkoMykyta force-pushed the issue-522-implementation-for-OpenSearch-Egress-Rules-lifecycle-workflow-on-APIv2 branch from 5ed815b to 67d506a Compare October 4, 2023 12:48
@OleksiienkoMykyta OleksiienkoMykyta force-pushed the issue-522-implementation-for-OpenSearch-Egress-Rules-lifecycle-workflow-on-APIv2 branch 2 times, most recently from 00a597d to c49d311 Compare October 20, 2023 13:13
Comment on lines 132 to 133
// This hack was added because the Instaclustr API returns an egress rule id with a null value, but it should be equal to the pattern {clusterId}~{source}~{bindingId}
// This code could be removed after the Instaclustr API team fixes this bug
Copy link
Collaborator

Choose a reason for hiding this comment

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

Remove this comment or move it in the right place

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

fixed

Comment on lines 2385 to 2389
// https://api.dev.instaclustr.com/cluster-management/v2/resources/applications/opensearch/egress-rules/v2/{egressRuleId}
fmt.Println(id)
url := c.serverHostname + OpenSearchEgressRulesEndpoint + "/" + id
fmt.Println("GOT:", url)
fmt.Println("expected: https://api.dev.instaclustr.com/cluster-management/v2/resources/applications/opensearch/egress-rules/v2/{egressRuleId}")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Remove unnecessary code please

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

fixed

@OleksiienkoMykyta OleksiienkoMykyta force-pushed the issue-522-implementation-for-OpenSearch-Egress-Rules-lifecycle-workflow-on-APIv2 branch from c49d311 to ef887fb Compare October 24, 2023 08:20
Comment on lines 60 to 66
if !slices.Contains(sourcePlugins, r.Spec.Source) || !slices.Contains(destinationTypes, r.Spec.Type) {
return fmt.Errorf("the source should be equeal to one of options: %q , got: %q. the type should be equeal to one of options: %q , got: %q", sourcePlugins, destinationTypes, r.Spec.Source, r.Spec.Type)
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

In my opinion, it will be better if you split it into 2 different conditions because the returning error looks unclear to me.

Suggested change
if !slices.Contains(sourcePlugins, r.Spec.Source) || !slices.Contains(destinationTypes, r.Spec.Type) {
return fmt.Errorf("the source should be equeal to one of options: %q , got: %q. the type should be equeal to one of options: %q , got: %q", sourcePlugins, destinationTypes, r.Spec.Source, r.Spec.Type)
}
if !slices.Contains(sourcePlugins, r.Spec.Source) {
return fmt.Errorf("the source should be equal to one of the options: %q , got: %q", sourcePlugins, r.Spec.Source)
}
if !slices.Contains(destinationTypes, r.Spec.Type) {
return fmt.Errorf("the type should be equal to one of the options: %q , got: %q", destinationTypes, r.Spec.Type
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

fixed

"errors"
"fmt"

"github.com/go-logr/logr"
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't want to say it but anyway someone will say So, please sort imports

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

fixed

Comment on lines 130 to 134
patch := rule.NewPatch()

err = r.Status().Patch(ctx, rule, patch)
Copy link
Collaborator

Choose a reason for hiding this comment

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

It looks a bit weird. As I understand here you patch an ID of the resource. I suggest you create another variable for self-composed ID and provide it anywhere you want. Then patch rule.Status.ID with the value of the created variable.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

fixed

Comment on lines 2345 to 2347
}
err = json.Unmarshal(b, &rule.Status)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
}
err = json.Unmarshal(b, &rule.Status)
}
err = json.Unmarshal(b, &rule.Status)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

fixed

}

func (c *Client) DeleteOpenSearchEgressRule(id string) error {
// https://api.dev.instaclustr.com/cluster-management/v2/resources/applications/opensearch/egress-rules/v2/{egressRuleId}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please delete this

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

fixed

Comment on lines 2375 to 2378
}
err = json.Unmarshal(b, &rule)
Copy link
Collaborator

Choose a reason for hiding this comment

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

A bit of code cleanup. Also do it in other similar cases if they exists

Suggested change
}
err = json.Unmarshal(b, &rule)
}
err = json.Unmarshal(b, &rule)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

fixed

@OleksiienkoMykyta OleksiienkoMykyta force-pushed the issue-522-implementation-for-OpenSearch-Egress-Rules-lifecycle-workflow-on-APIv2 branch from ef887fb to f45c633 Compare October 24, 2023 12:14
Comment on lines 19 to 40
import (
"context"
"errors"
"fmt"

clusterresourcesv1beta1 "github.com/instaclustr/operator/apis/clusterresources/v1beta1"
"github.com/instaclustr/operator/pkg/instaclustr"
"github.com/instaclustr/operator/pkg/models"
"github.com/instaclustr/operator/pkg/scheduler"

"github.com/go-logr/logr"
k8serrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
"k8s.io/client-go/tools/record"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
"sigs.k8s.io/controller-runtime/pkg/log"
)
Copy link
Contributor

Choose a reason for hiding this comment

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

instaclustr/operator imports go third.

if rule.DeletionTimestamp != nil {
err = r.handleDelete(ctx, l, rule)
if err != nil {
return models.ReconcileRequeue, err
Copy link
Contributor

Choose a reason for hiding this comment

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

please apply the custom rate limiter and remove models.ReconcileRequeue

@OleksiienkoMykyta OleksiienkoMykyta force-pushed the issue-522-implementation-for-OpenSearch-Egress-Rules-lifecycle-workflow-on-APIv2 branch 2 times, most recently from 37f6b61 to de72397 Compare October 26, 2023 10:11
@OleksiienkoMykyta OleksiienkoMykyta force-pushed the issue-522-implementation-for-OpenSearch-Egress-Rules-lifecycle-workflow-on-APIv2 branch from de72397 to c3559f8 Compare October 26, 2023 13:32
@ribaraka ribaraka merged commit c9cce62 into main Oct 26, 2023
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants