Compare commits

..

5 Commits

Author SHA1 Message Date
Andrey Melnikov
bd5641bedc fix: bash missing character 2021-03-26 13:00:59 -07:00
Andrey Melnikov
aeba4ee8a2 fix: separate windows sections as windows doesn't use $PWD.
remove: minikube section as that is no longer recommended.
2021-03-26 12:53:34 -07:00
Andrey Melnikov
d69f6a4947 Merge pull request #897 from Vafilor/fix/secret.updates
fix:  add error detection when environment variable is too long
2021-03-12 11:38:35 -08:00
Andrey Melnikov
b2119d86d0 fix: detect case where secret is too long. Also only log the secret name. In case of long secret values this would flood the console. 2021-03-12 10:42:52 -08:00
Rush Tehrani
9938b60118 Update README.md 2021-03-08 10:01:47 -08:00
3 changed files with 43 additions and 77 deletions

View File

@@ -4,6 +4,8 @@
Note: Up migrations are automatically executed when the application is run.
#### Linux / Mac
```bash
docker run --rm --mount type=bind,source="${PWD}",target=/root onepanel/helper:v1.0.0 goose -dir db/sql create <name> sql # Create migration in db/sql folder
docker run --rm --mount type=bind,source="${PWD}",target=/root onepanel/helper:v1.0.0 goose -dir db postgres "${DB_DATASOURCE_NAME}" up # Migrate the DB to the most recent version available
@@ -11,6 +13,15 @@ docker run --rm --mount type=bind,source="${PWD}",target=/root onepanel/helper:v
docker run --rm --mount type=bind,source="${PWD}",target=/root onepanel/helper:v1.0.0 goose help # See all available commands
```
#### Windows
```bash
docker run --rm --mount type=bind,source="%CD%",target=/root onepanel/helper:v1.0.0 goose -dir db/sql create wow sql # Create migration in db/sql folder
docker run --rm --mount type=bind,source="%CD%",target=/root onepanel/helper:v1.0.0 goose -dir db postgres "${DB_DATASOURCE_NAME}" up # Migrate the DB to the most recent version available
docker run --rm --mount type=bind,source="%CD%",target=/root onepanel/helper:v1.0.0 goose -dir db postgres "${DB_DATASOURCE_NAME}" down # Roll back the version by 1
docker run --rm --mount type=bind,source="%CD%",target=/root onepanel/helper:v1.0.0 goose help # See all available commands
```
### Local
Install `goose`:
@@ -64,86 +75,27 @@ Make sure that your `$GOBIN` is in your `$PATH`.
### Docker
Generate Go and Swagger APIs:
Generate Go and Swagger APIs
#### Linux / Mac
```bash
docker run --rm --mount type=bind,source="${PWD}",target=/root onepanel-helper:v1.0.0 make api version=1.0.0
docker run --rm --mount type=bind,source="${PWD}",target=/root onepanel/helper:v1.0.0 make api-internal version=1.0.0
```
#### Windows
```bash
docker run --rm --mount type=bind,source="%CD%",target=/root onepanel/helper:v1.0.0 make api-internal version=1.0.0
```
### Local Installation
Generate Go and Swagger APIs:
```bash
make api version=1.0.0
make api-internal version=1.0.0
```
## Minikube Debugging and Development
It is possible to access host resources with minikube.
- This means you can run core and core-ui on your machine, and have minikube
execute API calls to your machine.
NOTE:
- Do not use host access with Minikube and VMWare. This has been shown not to work
in our testing.
If you have a work-around, feel free to let us know.
To make this work, some setup is needed.
- Minikube started with driver=virtualbox
Get your Minikube ssh IP
https://minikube.sigs.k8s.io/docs/handbook/host-access/
```shell script
minikube ssh "route -n | grep ^0.0.0.0 | awk '{ print \$2 }'"
```
Example output:
```shell script
10.0.2.2
```
When running core api, add these ENV variables.
```shell script
ONEPANEL_CORE_SERVICE_HOST=10.0.2.2 # IP you just got
ONEPANEL_CORE_SERVICE_PORT=8888 # HTTP Port set in main.go
```
DB Access
- You will need to change the Postgres service from ClusterIP to NodePort
Run
```shell script
minikube service list
```
Look at Postgres, you'll see something like this:
```shell script
$ minikube service list
|----------------------|----------------------------------------|--------------------|--------------------------------|
| NAMESPACE | NAME | TARGET PORT | URL |
|----------------------|----------------------------------------|--------------------|--------------------------------|
| application-system | application-controller-manager-service | No node port |
| default | kubernetes | No node port |
| kube-system | kube-dns | No node port |
| kubernetes-dashboard | dashboard-metrics-scraper | No node port |
| kubernetes-dashboard | kubernetes-dashboard | No node port |
| onepanel | onepanel-core | http/8888 | http://192.168.99.101:32000 |
| | | grpc/8887 | http://192.168.99.101:32001 |
| onepanel | onepanel-core-ui | http/80 | http://192.168.99.101:32002 |
| onepanel | postgres | 5432 | http://192.168.99.101:31975 |
|----------------------|----------------------------------------|--------------------|--------------------------------|
```
Grab `http://192.168.99.101:31975`
Use this in main.go for the following lines:
```shell script
databaseDataSourceName := fmt.Sprintf("port=31975 host=%v user=%v password=%v dbname=%v sslmode=disable",
"192.168.99.101", config["databaseUsername"], config["databasePassword"], config["databaseName"])
```
This should connect your developing core to the minikube db.
After this, build main.go and run the executable.
- Or use your IDE equivalent
## Code Structure & Organization
### `utils` dir

View File

@@ -43,5 +43,5 @@ We are grateful for the support these communities provide and do our best to con
## License
Onepanel is licensed under [Apache 2.0](https://github.com/onepanelio/core/blob/master/LICENSE).
## Managed solution
Visit our [website](https://www.onepanel.ai/) for more information on our managed on-premises solution.
## For organizations
Visit our [website](https://www.onepanel.ai/) for more information on support options and enterprise solution.

View File

@@ -4,6 +4,7 @@ import (
"encoding/base64"
"encoding/json"
goerrors "errors"
"strings"
"github.com/onepanelio/core/pkg/util"
log "github.com/sirupsen/logrus"
@@ -225,7 +226,7 @@ func (c *Client) AddSecretKeyValue(namespace string, secret *Secret) (inserted b
}
}
if secretDataKeyExists {
errorMsg := "Key: " + key + " already exists in secret."
errorMsg := "Key '" + key + "' already exists"
return false, util.NewUserError(codes.AlreadyExists, errorMsg)
}
}
@@ -283,9 +284,15 @@ func (c *Client) AddSecretKeyValue(namespace string, secret *Secret) (inserted b
if err != nil {
log.WithFields(log.Fields{
"Namespace": namespace,
"Secret": secret,
"Secret": secret.Name,
"Error": err.Error(),
}).Error("Error adding key and value to Secret.")
if strings.Contains(err.Error(), "Request entity too large:") ||
strings.Contains(err.Error(), "Too long: must have at most") {
return false, util.NewUserError(codes.InvalidArgument, "Value is too long")
}
return false, util.NewUserError(codes.Unknown, "Error adding key and value to Secret.")
}
return true, nil
@@ -311,9 +318,10 @@ func (c *Client) UpdateSecretKeyValue(namespace string, secret *Secret) (updated
if err != nil {
log.WithFields(log.Fields{
"Namespace": namespace,
"Secret": secret,
"Secret": secret.Name,
"Error": err.Error(),
}).Error("Unable to find secret.")
return false, util.NewUserError(codes.NotFound, "Unable to find secret.")
}
secretDataKeyExists := false
@@ -344,9 +352,15 @@ func (c *Client) UpdateSecretKeyValue(namespace string, secret *Secret) (updated
if err != nil {
log.WithFields(log.Fields{
"Namespace": namespace,
"Secret": secret,
"Secret": secret.Name,
"Error": err.Error(),
}).Error("Unable to update secret key value.")
if strings.Contains(err.Error(), "Request entity too large:") ||
strings.Contains(err.Error(), "Too long: must have at most") {
return false, util.NewUserError(codes.InvalidArgument, "Value is too long")
}
return false, util.NewUserError(codes.Unknown, "Unable to update secret key value.")
}
return true, nil