Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion create/opensearch.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ import (
type openSearchCmd struct {
resourceCmd
Location string `help:"Location where the OpenSearch cluster is created." placeholder:"nine-es34"`
MachineType string `help:"MachineType specifies the type of machine to use for the OpenSearch cluster." placeholder:"nine-search-s"`
ClusterType storage.OpenSearchClusterType `help:"ClusterType specifies the type of OpenSearch cluster to create. Options: single, multi" placeholder:"single"`
MachineType string `help:"MachineType specifies the type of machine to use for the OpenSearch cluster." placeholder:"nine-search-s"`
AllowedCidrs []meta.IPv4CIDR `help:"AllowedCIDRs specify the allowed IP addresses, connecting to the cluster." placeholder:"203.0.113.1/32"`
BucketUsers []string `help:"BucketUsers specify the users who have read access to the OpenSearch snapshots bucket." placeholder:"user1,user2"`
}

func (cmd *openSearchCmd) Run(ctx context.Context, client *api.Client) error {
Expand Down Expand Up @@ -69,9 +70,20 @@ func (cmd *openSearchCmd) newOpenSearch(namespace string) (*storage.OpenSearch,
MachineType: infra.NewMachineType(cmd.MachineType),
ClusterType: cmd.ClusterType,
AllowedCIDRs: cmd.AllowedCidrs,
BucketUsers: LocalReferences(cmd.BucketUsers),
},
},
}

return openSearch, nil
}

// LocalReferences converts a slice of strings to []meta.LocalReference.
func LocalReferences(s []string) []meta.LocalReference {
references := make([]meta.LocalReference, len(s))
for i, user := range s {
references[i] = meta.LocalReference{Name: user}
}

return references
}
9 changes: 3 additions & 6 deletions update/opensearch.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@ import (
meta "github.com/ninech/apis/meta/v1alpha1"
storage "github.com/ninech/apis/storage/v1alpha1"
"github.com/ninech/nctl/api"
"github.com/ninech/nctl/create"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

type openSearchCmd struct {
resourceCmd
MachineType *string `help:"MachineType configures OpenSearch to use a specified machine type." placeholder:"nine-search-m"`
AllowedCidrs *[]meta.IPv4CIDR `help:"AllowedCIDRs specify the allowed IP addresses, connecting to the cluster." placeholder:"203.0.113.1/32"`
BucketUsers *[]string `help:"BucketUsers specify the users who have read access to the OpenSearch bucket." placeholder:"user1,user2"`
BucketUsers *[]string `help:"BucketUsers specify the users who have read access to the OpenSearch snapshots bucket." placeholder:"user1,user2"`
}

func (cmd *openSearchCmd) Run(ctx context.Context, client *api.Client) error {
Expand Down Expand Up @@ -49,11 +50,7 @@ func (cmd *openSearchCmd) applyUpdates(openSearch *storage.OpenSearch) error {
openSearch.Spec.ForProvider.AllowedCIDRs = *cmd.AllowedCidrs
}
if cmd.BucketUsers != nil {
bucketUsers := make([]meta.LocalReference, len(*cmd.BucketUsers))
for i, user := range *cmd.BucketUsers {
bucketUsers[i] = meta.LocalReference{Name: user}
}
openSearch.Spec.ForProvider.BucketUsers = bucketUsers
openSearch.Spec.ForProvider.BucketUsers = create.LocalReferences(*cmd.BucketUsers)
}

return nil
Expand Down