Skip to content

Commit

Permalink
Merge pull request #23 from redhat-marketplace/feature/multipleSources
Browse files Browse the repository at this point in the history
Feature/multiple sources
  • Loading branch information
dacleyra authored May 8, 2023
2 parents b05a6ba + 9be34f4 commit c332d60
Show file tree
Hide file tree
Showing 62 changed files with 3,383 additions and 682 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,5 @@
*.coverprofile
dist/
version.txt

bin/
35 changes: 34 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,33 @@
GO=go
GO_MAJOR_VERSION = $(shell $(GO) version | cut -c 14- | cut -d' ' -f1 | cut -d'.' -f1)
GO_MINOR_VERSION = $(shell $(GO) version | cut -c 14- | cut -d' ' -f1 | cut -d'.' -f2)
MINIMUM_SUPPORTED_GO_MAJOR_VERSION = 1
MINIMUM_SUPPORTED_GO_MINOR_VERSION = 19
MAXIMUM_SUPPORTED_GO_MINOR_VERSION = 19
GO_VERSION_VALIDATION_ERR_MSG = Golang version is not supported, please update to least $(MINIMUM_SUPPORTED_GO_MAJOR_VERSION).$(MINIMUM_SUPPORTED_GO_MINOR_VERSION)

.DEFAULT_GOAL := install

GOBIN := $(shell pwd)/bin
PATH := $(GOBIN):$(PATH)

export PATH
export GOBIN

validate-go-version: ## Validates the installed version of go against Mattermost's minimum requirement.
@if [ $(GO_MAJOR_VERSION) -gt $(MINIMUM_SUPPORTED_GO_MAJOR_VERSION) ]; then \
exit 0 ;\
elif [ $(GO_MAJOR_VERSION) -lt $(MINIMUM_SUPPORTED_GO_MAJOR_VERSION) ]; then \
echo '$(GO_VERSION_VALIDATION_ERR_MSG)';\
exit 1; \
elif [ $(GO_MINOR_VERSION) -lt $(MINIMUM_SUPPORTED_GO_MINOR_VERSION) ] ; then \
echo '$(GO_VERSION_VALIDATION_ERR_MSG)';\
exit 1; \
elif [ $(GO_MINOR_VERSION) -gt $(MAXIMUM_SUPPORTED_GO_MINOR_VERSION) ] ; then \
echo '$(GO_VERSION_VALIDATION_ERR_MSG)';\
exit 1; \
fi

.PHONY: tag
tag:
git tag $(svu next)
Expand All @@ -18,7 +46,7 @@ test:
ginkgo -r --randomize-all --randomize-suites --fail-on-pending --cover --trace --race --show-node-events

.PHONY: generate
generate:
generate: validate-go-version tools
go generate ./...

.PHONY: install
Expand All @@ -37,3 +65,8 @@ release: goreleaser
.PHONY: goreleaser
goreleaser:
go install github.com/goreleaser/[email protected]

tools:
go mod download
go install "k8s.io/code-generator/cmd/[email protected]"
go install "sigs.k8s.io/controller-tools/cmd/[email protected]"
48 changes: 41 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
- [Installation](#installation)
- [Usage](#usage)
- [Getting started](#getting-started)
- [Export](#export)
- [Exporting from DataService sources](#exporting-from-dataservice-sources)
- [Exporting from IBM License Metric Tool sources](#exporting-from-ibm-license-metric-tool-sources)

<!-- markdown-toc end -->

Expand Down Expand Up @@ -45,24 +46,30 @@ Datactl tool can be used standalone. Just move oc-datactl to your path and use `

4. Add the role-binding to the default service account on operator-namespace.

Install the role and role binding for the default service account for the `openshift-redhat-marketplace`
namespace. The datactl tool will use these by default.
Install the ClusterRole and create the ClusterRoleBinding for the default service account for the namespace the IBM Metrics Operator's
DataService is installed to `by default: redhat-marketplace`. The datactl tool will use this service account by default.

```sh
oc apply -f resources/service-account-role.yaml // file found in release
oc create clusterrolebinding rhm-files --clusterrole=rhm-files --serviceaccount=redhat-marketplace:default
```

5. Now you're configured. You can start using the export commands.

## Export
## Exporting from DataService sources

Recommended approach is to run the commands in this order:

```sh
// Must be logged in to the cluster
oc datactl export pull

// If you're in a connect
// Add the dataservice as a source, to which you are logged into with your current context
datactl sources add dataservice --use-default-context --insecure-skip-tls-verify=true --allow-self-signed=true --namespace=redhat-marketplace

// Pull the data from dataservice sources
oc datactl export pull --source-type=dataservice

// If you're connected to the internet
oc datactl export push
// If no errors from push.
Expand All @@ -71,14 +78,20 @@ oc datactl export commit
Let's break down what each one is doing.

`oc datactl sources add dataservice --use-default-context --insecure-skip-tls-verify=true --allow-self-signed=true --namespace=redhat-marketplace`

- Adds the default-context cluster's dataservice as a source for pulling
- Writes the source data-service-endpoint to `~/.datactl/config`
- The DataService to connect to is in the `redhat-marketplace` namespace
`oc datactl export pull`
- Pulls files from data service and stores them in a tar file under your `~/.datactl/data` folder.
- Writes the status of the files found in `~/.datactl/config`
`oc datactl export push`
- Pushes the files pulled to Red Hat Marketplace.
- Files pulled by the previous command are pushed to Red Hat Marketplace.
- If this process errors, do not commit. Retry the export push or open a support ticket.
`oc datactl export commit`
Expand All @@ -88,3 +101,24 @@ Let's break down what each one is doing.
- After some time, the files in dataservice will be cleaned up to save space.
If you want to transfer it somewhere else, you can find the tar file under your `~/.datactl/data/` directory.
## Exporting from IBM License Metric Tool sources
_Prerequisite_: API Token is required to get data from IBM License Metric Tool (ILMT). Login to your ILMT environment, go to _Profile_ and click _Show token_ under API Token section.
First step is to configure ILMT data source. Execute following command
`datactl sources add ilmt`
and provide ILMT hostname, port number and token
To pull data from ILMT, execute command
`datactl export pull --source-type=ilmt`
First time you will be asked to provide start date. Next time last synchronization date is stored in config file and will be updated to pull data from last synchronization date.
To push data to Red Hat Marketplace execute command
`datactl export push`
5 changes: 4 additions & 1 deletion cmd/datactl/app/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ import (

configcmd "github.com/redhat-marketplace/datactl/cmd/datactl/app/config"
"github.com/redhat-marketplace/datactl/cmd/datactl/app/metering"
"github.com/redhat-marketplace/datactl/cmd/datactl/app/sources"
"github.com/redhat-marketplace/datactl/pkg/datactl/config"
"github.com/redhat-marketplace/datactl/pkg/datactl/output"
"k8s.io/cli-runtime/pkg/genericclioptions"
"k8s.io/client-go/rest"
cliflag "k8s.io/component-base/cli/flag"
Expand All @@ -37,6 +37,8 @@ import (
"k8s.io/kubectl/pkg/util/term"

_ "embed"

"github.com/redhat-marketplace/datactl/pkg/printers/output"
)

var (
Expand Down Expand Up @@ -146,6 +148,7 @@ func NewDatactlCommand(in io.Reader, out, err io.Writer) *cobra.Command {
Message: "Metering Commands:",
Commands: []*cobra.Command{
metering.NewCmdExport(rhmConfigFlags, f, ioStreams),
sources.NewCmdSources(rhmConfigFlags, f, ioStreams),
},
},
{
Expand Down
Loading

0 comments on commit c332d60

Please sign in to comment.