-
Notifications
You must be signed in to change notification settings - Fork 8
feat: add opensearch resource #266
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
Merged
Merged
Changes from 11 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
e1203ac
feat: add support for opensearch
josi19 b6bc954
feat: add support for opensearch and add test cases
josi19 1694d32
build: update api package
josi19 b58a3ee
build: go mod tidy
josi19 42be94e
fix: adapt to rebase and fixed tests
josi19 6a80e90
refactor: small changes based on PR inputs
josi19 f330cb1
refactor: cleanup unused function
josi19 42d18bb
fix: fixed print user/password function
josi19 730ebd6
fix: better handling if no update parameter is provided
josi19 2a05512
feat: add option to print cacert for os instance / removed public net…
josi19 567ffad
feat: add option to print configured Allowed CIDRS
josi19 813e67a
refactor: remove --print-allowed-cidrs to keep the parameters consistent
josi19 9677bf6
refacor: minor changes based on pr inputs
josi19 6e7c797
chore: rename instance to cluster in descriptions
josi19 bcc1511
fix: fix os update tests
josi19 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| package create | ||
|
|
||
| import ( | ||
| "context" | ||
|
|
||
| runtimev1 "github.com/crossplane/crossplane-runtime/apis/common/v1" | ||
| infra "github.com/ninech/apis/infrastructure/v1alpha1" | ||
| meta "github.com/ninech/apis/meta/v1alpha1" | ||
| storage "github.com/ninech/apis/storage/v1alpha1" | ||
| "github.com/ninech/nctl/api" | ||
| metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
| "k8s.io/apimachinery/pkg/watch" | ||
| ) | ||
|
|
||
| type openSearchCmd struct { | ||
| resourceCmd | ||
| Location string `help:"Location where the OpenSearch instance is created." placeholder:"nine-es34"` | ||
| MachineType string `help:"MachineType specifies the type of machine to use for the OpenSearch instance." placeholder:"nine-search-s"` | ||
| ClusterType storage.OpenSearchClusterType `help:"ClusterType specifies the type of OpenSearch cluster to create. Options: single, multi" placeholder:"single"` | ||
| AllowedCidrs []meta.IPv4CIDR `help:"AllowedCIDRs specify the allowed IP addresses, connecting to the instance." placeholder:"203.0.113.1/32"` | ||
| } | ||
|
|
||
| func (cmd *openSearchCmd) Run(ctx context.Context, client *api.Client) error { | ||
| openSearch, err := cmd.newOpenSearch(client.Project) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| c := newCreator(client, openSearch, "opensearch") | ||
| ctx, cancel := context.WithTimeout(ctx, cmd.WaitTimeout) | ||
| defer cancel() | ||
|
|
||
| if err := c.createResource(ctx); err != nil { | ||
| return err | ||
| } | ||
|
|
||
| if !cmd.Wait { | ||
| return nil | ||
| } | ||
|
|
||
| return c.wait(ctx, waitStage{ | ||
| objectList: &storage.OpenSearchList{}, | ||
| onResult: func(event watch.Event) (bool, error) { | ||
| if c, ok := event.Object.(*storage.OpenSearch); ok { | ||
| return isAvailable(c), nil | ||
| } | ||
| return false, nil | ||
| }, | ||
| }) | ||
| } | ||
|
|
||
| func (cmd *openSearchCmd) newOpenSearch(namespace string) (*storage.OpenSearch, error) { | ||
| name := getName(cmd.Name) | ||
|
|
||
| openSearch := &storage.OpenSearch{ | ||
| ObjectMeta: metav1.ObjectMeta{ | ||
| Name: name, | ||
| Namespace: namespace, | ||
| }, | ||
| Spec: storage.OpenSearchSpec{ | ||
| ResourceSpec: runtimev1.ResourceSpec{ | ||
| WriteConnectionSecretToReference: &runtimev1.SecretReference{ | ||
| Name: "opensearch-" + name, | ||
| Namespace: namespace, | ||
| }, | ||
| }, | ||
| ForProvider: storage.OpenSearchParameters{ | ||
| Location: meta.LocationName(cmd.Location), | ||
| MachineType: infra.NewMachineType(cmd.MachineType), | ||
| ClusterType: cmd.ClusterType, | ||
| AllowedCIDRs: cmd.AllowedCidrs, | ||
| }, | ||
| }, | ||
| } | ||
|
|
||
| return openSearch, nil | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| package create | ||
|
|
||
| import ( | ||
| "context" | ||
| "testing" | ||
| "time" | ||
|
|
||
| "github.com/google/go-cmp/cmp" | ||
| infra "github.com/ninech/apis/infrastructure/v1alpha1" | ||
| meta "github.com/ninech/apis/meta/v1alpha1" | ||
| storage "github.com/ninech/apis/storage/v1alpha1" | ||
| "github.com/ninech/nctl/api" | ||
| "github.com/ninech/nctl/internal/test" | ||
| "github.com/stretchr/testify/require" | ||
| metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
| ) | ||
|
|
||
| func TestOpenSearch(t *testing.T) { | ||
| ctx := context.Background() | ||
| tests := []struct { | ||
| name string | ||
| create openSearchCmd | ||
| want storage.OpenSearchParameters | ||
| wantErr bool | ||
| }{ | ||
| { | ||
| name: "default", | ||
| want: storage.OpenSearchParameters{}, | ||
| }, | ||
| { | ||
| name: "customLocation", | ||
| create: openSearchCmd{Location: "nine-cz41"}, | ||
| want: storage.OpenSearchParameters{ | ||
| Location: meta.LocationNineCZ41, | ||
| }, | ||
| }, | ||
| { | ||
| name: "multiClusterType", | ||
| create: openSearchCmd{ClusterType: storage.OpenSearchClusterTypeMulti}, | ||
| want: storage.OpenSearchParameters{ | ||
| ClusterType: storage.OpenSearchClusterTypeMulti, | ||
| }, | ||
| }, | ||
| { | ||
| name: "customMachineType", | ||
| create: openSearchCmd{MachineType: infra.MachineTypeNineSearchL.String()}, | ||
| want: storage.OpenSearchParameters{ | ||
| MachineType: infra.MachineTypeNineSearchL, | ||
| }, | ||
| }, | ||
| { | ||
| name: "allowedCIDRs", | ||
| create: openSearchCmd{ | ||
| AllowedCidrs: []meta.IPv4CIDR{meta.IPv4CIDR("192.168.1.0/24")}, | ||
| }, | ||
| want: storage.OpenSearchParameters{ | ||
| AllowedCIDRs: []meta.IPv4CIDR{meta.IPv4CIDR("192.168.1.0/24")}, | ||
| }, | ||
| }, | ||
| } | ||
| for _, tt := range tests { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| tt.create.Name = "test-" + t.Name() | ||
| tt.create.Wait = false | ||
| tt.create.WaitTimeout = time.Second | ||
|
|
||
| apiClient, err := test.SetupClient() | ||
| require.NoError(t, err) | ||
|
|
||
| if err := tt.create.Run(ctx, apiClient); (err != nil) != tt.wantErr { | ||
| t.Errorf("openSearchCmd.Run() error = %v, wantErr %v", err, tt.wantErr) | ||
| } | ||
|
|
||
| created := &storage.OpenSearch{ObjectMeta: metav1.ObjectMeta{Name: tt.create.Name, Namespace: apiClient.Project}} | ||
| if err := apiClient.Get(ctx, api.ObjectName(created), created); (err != nil) != tt.wantErr { | ||
| t.Fatalf("expected opensearch to exist, got: %s", err) | ||
| } | ||
| if tt.wantErr { | ||
| return | ||
| } | ||
|
|
||
| require.True(t, cmp.Equal(tt.want, created.Spec.ForProvider)) | ||
| }) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| package delete | ||
|
|
||
| import ( | ||
| "context" | ||
|
|
||
| storage "github.com/ninech/apis/storage/v1alpha1" | ||
| "github.com/ninech/nctl/api" | ||
| metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
| ) | ||
|
|
||
| type openSearchCmd struct { | ||
| resourceCmd | ||
| } | ||
|
|
||
| func (cmd *openSearchCmd) Run(ctx context.Context, client *api.Client) error { | ||
| ctx, cancel := context.WithTimeout(ctx, cmd.WaitTimeout) | ||
| defer cancel() | ||
|
|
||
| openSearch := &storage.OpenSearch{ObjectMeta: metav1.ObjectMeta{Name: cmd.Name, Namespace: client.Project}} | ||
| return newDeleter(openSearch, storage.OpenSearchKind).deleteResource(ctx, client, cmd.WaitTimeout, cmd.Wait, cmd.Force) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| package delete | ||
|
|
||
| import ( | ||
| "context" | ||
| "testing" | ||
| "time" | ||
|
|
||
| "github.com/ninech/nctl/api" | ||
| "github.com/ninech/nctl/internal/test" | ||
| "github.com/stretchr/testify/require" | ||
| "k8s.io/apimachinery/pkg/api/errors" | ||
| ) | ||
|
|
||
| func TestOpenSearch(t *testing.T) { | ||
| ctx := context.Background() | ||
| cmd := openSearchCmd{ | ||
| resourceCmd: resourceCmd{ | ||
| Name: "test", | ||
| Force: true, | ||
| Wait: false, | ||
| WaitTimeout: time.Second, | ||
| }, | ||
| } | ||
|
|
||
| opensearch := test.OpenSearch("test", test.DefaultProject, "nine-es34") | ||
|
|
||
| apiClient, err := test.SetupClient() | ||
| require.NoError(t, err) | ||
|
|
||
| if err := apiClient.Create(ctx, opensearch); err != nil { | ||
| t.Fatalf("opensearch create error, got: %s", err) | ||
| } | ||
| if err := apiClient.Get(ctx, api.ObjectName(opensearch), opensearch); err != nil { | ||
| t.Fatalf("expected opensearch to exist, got: %s", err) | ||
| } | ||
| if err := cmd.Run(ctx, apiClient); err != nil { | ||
| t.Fatal(err) | ||
| } | ||
| err = apiClient.Get(ctx, api.ObjectName(opensearch), opensearch) | ||
| if err == nil { | ||
| t.Fatalf("expected opensearch to be deleted, but exists") | ||
| } | ||
| if !errors.IsNotFound(err) { | ||
| t.Fatalf("expected opensearch to be deleted, got: %s", err.Error()) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.