Skip to content

Commit

Permalink
feat(nomad): add Nomad environment option [EE-2896] (#1494)
Browse files Browse the repository at this point in the history
* feat(environment): introduce nomad [EE-1866] (#1308)

* feat(nomad): support nomad in edge stack EE-2467 (#1179)

* init commit for supporting nomad edge stack

* update job parser

* refactor edge stack update logic

* comment fix

* simplify nomad job file naming

* tag updates

* update nomad stack deployment type logic

* update deployment type logic

* feat(nomad): EE-2474 allow agent to register itself as an EdgeAgentOnNomadEnvironment

* feat(nomad) EE-2504 show nomad endpoint on homepage (#1202)

* feat(nomad) EE-2504 add nomad icon

* feat(nomad) EE-2504 show nomad endpoint on homepage

Co-authored-by: Simon Meng <simon.meng@portainer.io>

* feat(nomad) EE-2507 nomad environment setup screen (#1203)

* feat(nomad) EE-2507 nomad environment setup screen

* EE-2533 support nomad type in edge group create (#1228)

* feat(nomad) EE-2508 snapshot nomad (#1244)

* feat(nomad) EE-2562 enable creation of edge group and stack (#1245)

* feat(nomad) BE: count nomad as an edge endpoint

* feat(nomad) FE: count nomad as an edge endpoint

* feat(nomad) FE: show button of nomad deployment type

* feat(nomad) FE: add nomad hcl form

Co-authored-by: Simon Meng <simon.meng@portainer.io>

* feat(nomad) EE-2510 dashboard for nomad (#1256)

* feat(nomad) EE-2510 navigate to nomad.dashboard when click nomad endpiont

* feat(nomad) EE-2510 add nomad module skeleton

* feat(nomad) EE-2510 add DashboardItem component

* feat(nomad) EE-2510 add RunningStatus component

* feat(nomad) EE-2510 add react hook for loading environment

* feat(nomad) EE-2510 add react hook for loading environment ID

* feat(nomad) EE-2510 add dashboard view of nomad

* feat(nomad) EE-2510 cleanup code

Co-authored-by: Simon Meng <simon.meng@portainer.io>

* feat(nomad): left side menu for nomad [EE-2564] (#1261)

* feat(nomad): left side menu for nomad [EE-2564]

* support NOMAD as an endpoint type

* add tests + story

* add endpoint information to applicationState

* fixes based on suggestions in azure work

* feat(nomad): add nomad job events handler EE-2515 (#1251)

* add nomad job events handler

* update subhandler logic

* init datastore for nomad handler

* move events to task level

* Feat(nomad) EE-1866/EE-2512 nomad job list view (#1301)

* feat(nomad) EE-2512 add skeleton of job list

* feat(nomad) EE-2512 add onReload callback function for PageHeader

* feat(nomad) EE-2512 add refresh button to update snapshot

* feat(nomad) EE-2512 collect more tasks and allocations information to snapshot

* feat(nomad) EE-2512 populate data from snapshot to jobs table

* feat(nomad) EE-2512 enable filter for task status column of tasks table

* feat(nomad) EE-2512 store SubmitTime as unix seconds instead of unix microseconds

* feat(nomad) EE-2512 format Created time

* feat(nomad) EE-2512 format StartedAt time

* feat(nomad) EE-2512 add actions for tasks table

* feat(nomad) EE-2512 upgrade module @fortawesome/fontawesome-free

* feat(nomad) EE-2512 add actions for jobs table

* feat(nomad) EE-2512 color task state

* feat(nomad) EE-2512 remove link from job name

* feat(nomad) EE-2512 add job actions

* feat(nomad) EE-2512 add delete job endpoint

* feat(nomad) EE-2512 add delete job method for nomad client

* feat(nomad) EE-2512 add delete job rest

* feat(nomad) EE-2512 call delete job rest

* feat(nomad) EE-2512 add loading spinner to PageHeader

* feat(nomad) EE-2512 show loading spinner when refresh jobs

* feat(nomad) EE-2512 add namespace to related nomad client interface

* feat(nomad) EE-2512 display namespace column for jobs table

* feat(nomad) EE-2512 pass namespace to endpoint when deleting a job

* feat(nomad) EE-2512 display spinner when deleting jobs

* feat(nomad) EE-2512 refresh jobs table after deleting jobs

* feat(nomad) EE-2512 cleanup code

* feat(nomad) EE-2512 set endpoint ID when entering nomad environment

* feat(nomad) EE-2512 show dash for tasks when no snapshot is available

* feat(nomad) EE-2512 update jobs view header title and desc

* feat(nomad) EE-2512 align action icons center for jobs and tasks tables

* Revert "feat(nomad) EE-2512 upgrade module @fortawesome/fontawesome-free"

This reverts commit 4318ef8167359daad1136f8d3aa369cff5509803.

* feat(nomad) EE-2512 downgrad module @fortawesome/fontawesome-free

* feat(nomad) EE-2512 add web editor form for nomad edge stack

Co-authored-by: Simon Meng <simon.meng@portainer.io>

* feat(nomad): task events handler updates EE-2732 (#1307)

* task event handler updates

* Update api/http/handler/nomad/handler.go

* Update api/http/handler/edgestacks/edgestack_create.go

Co-authored-by: Chaim Lev-Ari <chiptus@users.noreply.github.com>

* fix typo

* feat(environments): show nomad name and icon in table [EE-2692] (#1322)

* feat(app): add nomad icon

* refactor(environments): generate endpoint type name

* feat(environments): show nomad icon

* refactor(nomad): folder structure and rq [EE-2750] (#1319)

* feat(nomad): populate cluster info [EE-2755] (#1325)

* feat(wizard): add nomad env [EE-2749] (#1320)

* feat(nomad) EE-2739 remove nomad address input box (#1337)

Co-authored-by: Simon Meng <simon.meng@portainer.io>

* refactor(nomad): use useMutation to delete jobs (#1332)

* feat(nomad): EE-2517 support retrieving nomad task logs (#1297)

* add nomad task logs handler

* stream change

* update nomad log streaming logic

* task logs handler updates

* add offset param and cleanup

* rename tunnelAddress

* feat(nomad) EE-2754 refresh jobs and snapshot (#1329)

Co-authored-by: Simon Meng <simon.meng@portainer.io>

* feat(nomad) EE-1866/EE-2514 nomad events view (#1311)

* feat(nomad) EE-2514 add more info to nomad task for task events

* feat(nomad) EE-2514 nomad job events view

Co-authored-by: Simon Meng <simon.meng@portainer.io>

* feat(nomad) EE-1866/EE-2509 nomad edit edge stack (#1343)

* feat(nomad) EE-2509 save changes when editing nomad edge stack

* feat(nomad) EE-2509 rewrite EdgeStackDeploymentTypeSelector with react

* feat(nomad) EE-2509 disable invalid deployment type buttons when edge groups change

Co-authored-by: Simon Meng <simon.meng@portainer.io>

* fix(deployment): fix copy button [EE-2780] (#1352)

* fix(deployment): fix copy button [EE-2780]

* fix displayed agent version

* feat(nomad) EE-1866/EE-2519 pass env vars to agent installation command (#1355)

* fix(wizard): remove nomad address and add copy button (#1346)

* extra checks and improvements

* feat(nomad) EE-1866/EE-2766 make nomad token optional (#1357)

Co-authored-by: Simon Meng <simon.meng@portainer.io>

Co-authored-by: Hui <arris_li@hotmail.com>
Co-authored-by: cong meng <mcpacino@gmail.com>
Co-authored-by: Simon Meng <simon.meng@portainer.io>
Co-authored-by: itsconquest <william.conquest@portainer.io>

* fix conflicts

* fix(environments): show nomad details when associated (#1353)

* refactor(nomad): make additional changes [EE-2776] (#1349)

* fix(nomad): fix nomad module file for release [EE-2789] (#1366)

* fix(nomad) EE-2794 fix validation of tunnel (#1368)

* fix(nomad) EE-2794 fix validation of tunnel

* fix(nomad) EE-2794 set tunnel to ideal only when hitting connection refused error

Co-authored-by: Simon Meng <simon.meng@portainer.io>

* fix(edge): show kube and nomad edge devices [EE-2790] (#1373)

fix [EE-2790]

* feat(nomad-log): added nomad log (#1365)

* feat(nomad-log): decode log data

* feat(nomad-log): added nomad logs component

* feat(nomad-log): added nomad-log-viewer component

* feat(nomad-log): uploaded log link url

* feat(nomad-log): updated error message

* feat(nomad-log): update how AbortController works.

* feat(nomad-log): fixed AbortController

* feat(nomad-log): only show no logs place holder when auto refresh is off

* fix(nomd) EE-2793 nomad de-associate produces error (#1370)

* fix(nomad) EE-2793 allow users to de-associate a nomad endpoint

* fix(nomad) EE-2793 display correct platform name

Co-authored-by: Simon Meng <simon.meng@portainer.io>

* fix(nomad) EE-2817 fix nil reference (#1383)

Co-authored-by: Simon Meng <simon.meng@portainer.io>

* fix(nomad) EE-2804 allow authenticated users to get events and logs (#1377)

Co-authored-by: Simon Meng <simon.meng@portainer.io>

* fix(app): remove link from nav tabs [EE-2795] (#1372)

* feat(nomad/jobs): remove delete button [EE-2805] (#1375)

* fix(wizard): add env vars field to nomad [EE-2792] (#1371)

* fix(nomad): use font icon instead of png [EE-2799] (#1374)

* fix(nomad) EE-2758 update text of agent buttons (#1390)

Co-authored-by: Simon Meng <simon.meng@portainer.io>

* fix(nomad) EE-2806 fix browse button (#1378)

Co-authored-by: Simon Meng <simon.meng@portainer.io>

* feat(nomad-log): close API connection when component is destroyed (#1387)

* Fix(nomad) EE-2823 nomad misc fixes (#1397)

* fix(nomad) EE-2823 replace text 'jobs' with 'nomad jobs'

* fix(nomad) EE-2823 make job actions column un-sortable

* fix(nomad) EE-2823 click job action to expand the sub row of tasks

* fix(nomad) EE-2823 update nomad logo with transparent bakcgorund

* fix(nomad) EE-2823 display tooltip for Nomad Authentication Toggle

* fix(nomad) EE-2823 add warning of not support https

* fix(nomad) EE-2823 add the icon of nomad edge stack button

* fix(nomad) EE-2823 display pending status in yellow color

* fix(nomad) EE-2823 add space after the power button icons

Co-authored-by: Simon Meng <simon.meng@portainer.io>

* fix(edge): show nomad envs on edge groups [EE-2819] (#1388)

* fix(nomad): fix display of edge polling interval for release [EE-2827] (#1392)

* fix(edge): allow use of dynamic groups with nomad [EE-2839] (#1398)

fixes [EE-2839]

* fix(progress-bar): removed overrided css of angular-loading-bar (#1402)

* fix(edge/stacks): redirect to correct edit type [EE-2831] (#1403)

* prettier changes

* fix(home): load nomad env

* fix(env): rename getDashboardRoute

* refator: remove empty returns

* feat(home): show nomad icon and stats

* refacotr(env): remove PlatformNames

* refactor(home): remove unused files

* fix(edge): calculate is unassociated correctly

* refactor(edge): remove unused functions

* fix(environment): show platform type

* refactor(wizard): remove unused prop

* refactor: remove named returns

* feat(nomad) EE-1866 fix go.mod

* feat(nomad) EE-1866 add nomad command generator fucntion

* feat(nomad) EE-1866 fix download URL for nomad agent script

* fix(app): hide copied text

* feat(edge): add nomad scripts

* refactor(edge): use one place for all scripts

* rename script element to appease TS

* fix: nomad script

* fix: nomad script format

Co-authored-by: Dmitry Salakhov <to@dimasalakhov.com>
Co-authored-by: Hui <arris_li@hotmail.com>
Co-authored-by: Simon Meng <simon.meng@portainer.io>
Co-authored-by: itsconquest <william.conquest@portainer.io>
Co-authored-by: Chaim Lev-Ari <chiptus@users.noreply.github.com>
Co-authored-by: fhanportainer <79428273+fhanportainer@users.noreply.github.com>
Co-authored-by: Chaim Lev-Ari <chiptus@gmail.com>
  • Loading branch information
8 people committed Apr 20, 2022
1 parent fb26ed0 commit 3ca72a2
Show file tree
Hide file tree
Showing 179 changed files with 4,126 additions and 486 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -18,3 +18,4 @@ test/e2e/cypress/screenshots
__debug_bin
api/docs
.env
/.vscode/
22 changes: 19 additions & 3 deletions api/cmd/portainer/main.go
Expand Up @@ -36,6 +36,8 @@ import (
kubecli "github.com/portainer/portainer-ee/api/kubernetes/cli"
"github.com/portainer/portainer-ee/api/ldap"
"github.com/portainer/portainer-ee/api/license"
"github.com/portainer/portainer-ee/api/nomad/clientFactory"
nomadSnapshot "github.com/portainer/portainer-ee/api/nomad/snapshot"
"github.com/portainer/portainer-ee/api/oauth"
"github.com/portainer/portainer-ee/api/scheduler"
"github.com/portainer/portainer-ee/api/stacks"
Expand Down Expand Up @@ -255,11 +257,23 @@ func initKubernetesClientFactory(signatureService portaineree.DigitalSignatureSe
return kubecli.NewClientFactory(signatureService, reverseTunnelService, dataStore, instanceID)
}

func initSnapshotService(snapshotInterval string, dataStore dataservices.DataStore, dockerClientFactory *docker.ClientFactory, kubernetesClientFactory *kubecli.ClientFactory, shutdownCtx context.Context) (portaineree.SnapshotService, error) {
func initNomadClientFactory(signatureService portaineree.DigitalSignatureService, reverseTunnelService portaineree.ReverseTunnelService, dataStore dataservices.DataStore, instanceID string) *clientFactory.ClientFactory {
return clientFactory.NewClientFactory(signatureService, reverseTunnelService, dataStore, instanceID)
}

func initSnapshotService(
snapshotInterval string,
dataStore dataservices.DataStore,
dockerClientFactory *docker.ClientFactory,
kubernetesClientFactory *kubecli.ClientFactory,
nomadClientFactory *clientFactory.ClientFactory,
shutdownCtx context.Context,
) (portaineree.SnapshotService, error) {
dockerSnapshotter := docker.NewSnapshotter(dockerClientFactory)
kubernetesSnapshotter := kubernetes.NewSnapshotter(kubernetesClientFactory)
nomadSnapshotter := nomadSnapshot.NewSnapshotter(nomadClientFactory)

snapshotService, err := snapshot.NewService(snapshotInterval, dataStore, dockerSnapshotter, kubernetesSnapshotter, shutdownCtx)
snapshotService, err := snapshot.NewService(snapshotInterval, dataStore, dockerSnapshotter, kubernetesSnapshotter, nomadSnapshotter, shutdownCtx)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -636,8 +650,9 @@ func buildServer(flags *portaineree.CLIFlags) portainer.Server {

dockerClientFactory := initDockerClientFactory(digitalSignatureService, reverseTunnelService)
kubernetesClientFactory := initKubernetesClientFactory(digitalSignatureService, reverseTunnelService, dataStore, instanceID)
nomadClientFactory := initNomadClientFactory(digitalSignatureService, reverseTunnelService, dataStore, instanceID)

snapshotService, err := initSnapshotService(*flags.SnapshotInterval, dataStore, dockerClientFactory, kubernetesClientFactory, shutdownCtx)
snapshotService, err := initSnapshotService(*flags.SnapshotInterval, dataStore, dockerClientFactory, kubernetesClientFactory, nomadClientFactory, shutdownCtx)
if err != nil {
logrus.Fatalf("failed initializing snapshot service: %s", err)
}
Expand Down Expand Up @@ -778,6 +793,7 @@ func buildServer(flags *portaineree.CLIFlags) portainer.Server {
UserActivityService: userActivityService,
UserActivityStore: userActivityStore,
KubernetesClientFactory: kubernetesClientFactory,
NomadClientFactory: nomadClientFactory,
Scheduler: scheduler,
ShutdownCtx: shutdownCtx,
ShutdownTrigger: shutdownTrigger,
Expand Down
6 changes: 5 additions & 1 deletion api/go.mod
Expand Up @@ -26,6 +26,7 @@ require (
github.com/gorilla/securecookie v1.1.1
github.com/gorilla/websocket v1.5.0
github.com/hashicorp/golang-lru v0.5.4
github.com/hashicorp/nomad/api v0.0.0-20220128200432-22bd08912af7
github.com/joho/godotenv v1.4.0
github.com/jpillora/chisel v0.0.0-20190724232113-f3a8df20e389
github.com/json-iterator/go v1.1.12
Expand Down Expand Up @@ -84,6 +85,9 @@ require (
github.com/google/gofuzz v1.2.0 // indirect
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect
github.com/googleapis/gnostic v0.5.5 // indirect
github.com/hashicorp/cronexpr v1.1.1 // indirect
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
github.com/hashicorp/go-rootcerts v1.0.2 // indirect
github.com/imdario/mergo v0.3.12 // indirect
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
Expand All @@ -93,7 +97,7 @@ require (
github.com/kevinburke/ssh_config v0.0.0-20201106050909-4977a11b4351 // indirect
github.com/leodido/go-urn v1.2.1 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/mitchellh/mapstructure v1.1.2 // indirect
github.com/mitchellh/mapstructure v1.4.3 // indirect
github.com/moby/spdystream v0.2.0 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
Expand Down
14 changes: 13 additions & 1 deletion api/go.sum
Expand Up @@ -365,6 +365,7 @@ github.com/docker/go-events v0.0.0-20170721190031-9461782956ad/go.mod h1:Uw6Uezg
github.com/docker/go-events v0.0.0-20190806004212-e31b211e4f1c/go.mod h1:Uw6UezgYA44ePAFQYUehOuCzmy5zmg/+nl2ZfMWGkpA=
github.com/docker/go-metrics v0.0.0-20180209012529-399ea8c73916/go.mod h1:/u0gXw0Gay3ceNrsHubL3BtdOL2fHf93USgMTe0W5dI=
github.com/docker/go-metrics v0.0.1/go.mod h1:cG1hvH2utMXtqgqqYE9plW6lDxS3/5ayHzueweSI3Vw=
github.com/docker/go-units v0.3.3/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk=
github.com/docker/go-units v0.4.0 h1:3uh0PgVws3nIA0Q+MwDC8yjEPf9zjRfZZWXZYDct3Tw=
github.com/docker/go-units v0.4.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk=
github.com/docker/libtrust v0.0.0-20150114040149-fa567046d9b1/go.mod h1:cyGadeNEkKy96OOhEzfZl+yxihPEzKnqJwvfuSUqbZE=
Expand Down Expand Up @@ -603,16 +604,22 @@ github.com/grpc-ecosystem/grpc-gateway v1.9.5/go.mod h1:vNeuVxBJEsws4ogUvrchl83t
github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw=
github.com/hashicorp/consul/api v1.1.0/go.mod h1:VmuI/Lkw1nC05EYQWNKwWGbkg+FbDBtguAZLlVdkD9Q=
github.com/hashicorp/consul/sdk v0.1.1/go.mod h1:VKf9jXwCTEY1QZP2MOLRhb5i/I/ssyNV1vwHyQBF0x8=
github.com/hashicorp/cronexpr v1.1.1 h1:NJZDd87hGXjoZBdvyCF9mX4DCq5Wy7+A/w+A7q0wn6c=
github.com/hashicorp/cronexpr v1.1.1/go.mod h1:P4wA0KBl9C5q2hABiMO7cp6jcIg96CDh1Efb3g1PWA4=
github.com/hashicorp/errwrap v0.0.0-20141028054710-7554cd9344ce/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
github.com/hashicorp/errwrap v1.1.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
github.com/hashicorp/go-cleanhttp v0.5.1/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80=
github.com/hashicorp/go-cleanhttp v0.5.2 h1:035FKYIWjmULyFRBKPs8TBQoi0x6d9G4xc9neXJWAZQ=
github.com/hashicorp/go-cleanhttp v0.5.2/go.mod h1:kO/YDlP8L1346E6Sodw+PrpBSV4/SoxCXGY6BqNFT48=
github.com/hashicorp/go-immutable-radix v1.0.0/go.mod h1:0y9vanUI8NX6FsYoO3zeMjhV/C5i9g4Q3DwcSNZ4P60=
github.com/hashicorp/go-msgpack v0.5.3/go.mod h1:ahLV/dePpqEmjfWmKiqvPkv/twdG7iPBM1vqhUKIvfM=
github.com/hashicorp/go-multierror v0.0.0-20161216184304-ed905158d874/go.mod h1:JMRHfdO9jKNzS/+BTlxCjKNQHg/jZAft8U7LloJvN7I=
github.com/hashicorp/go-multierror v1.0.0/go.mod h1:dHtQlpGsu+cZNNAkkCN/P3hoUDHhCYQXV3UM06sGGrk=
github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM=
github.com/hashicorp/go-rootcerts v1.0.0/go.mod h1:K6zTfqpRlCUIjkwsN4Z+hiSfzSTQa6eBIzfwKfwNnHU=
github.com/hashicorp/go-rootcerts v1.0.2 h1:jzhAVGtqPKbwpyCPELlgNWhE1znq+qwJtW5Oi2viEzc=
github.com/hashicorp/go-rootcerts v1.0.2/go.mod h1:pqUvnprVnM5bf7AOirdbb01K4ccR319Vf4pU3K5EGc8=
github.com/hashicorp/go-sockaddr v1.0.0/go.mod h1:7Xibr9yA9JjQq1JpNB2Vw7kxv8xerXegt+ozgdvDeDU=
github.com/hashicorp/go-syslog v1.0.0/go.mod h1:qPfqrKkXGihmCqbJM2mZgkZGvKG1dFdvsLplgctolz4=
github.com/hashicorp/go-uuid v1.0.0/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
Expand All @@ -626,6 +633,8 @@ github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T
github.com/hashicorp/logutils v1.0.0/go.mod h1:QIAnNjmIWmVIIkWDTG1z5v++HQmx9WQRO+LraFDTW64=
github.com/hashicorp/mdns v1.0.0/go.mod h1:tL+uN++7HEJ6SQLQ2/p+z2pH24WQKWjBPkE0mNTz8vQ=
github.com/hashicorp/memberlist v0.1.3/go.mod h1:ajVTdAv/9Im8oMAAj5G31PhhMCZJV2pPBoIllUwCN7I=
github.com/hashicorp/nomad/api v0.0.0-20220128200432-22bd08912af7 h1:pIdMySD2reh+xBG/Tx67+x3+uQK3WkWxjKNbeaKuDgw=
github.com/hashicorp/nomad/api v0.0.0-20220128200432-22bd08912af7/go.mod h1:OcvjEDY+xMVaMl2/ev+Esz/IdJ529Qyrhc5ZQ6fq7AE=
github.com/hashicorp/serf v0.8.2/go.mod h1:6hOLApaqBFA1NXqRQAsxw9QxuDEvNxSQRwA/JwenrHc=
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
Expand Down Expand Up @@ -733,11 +742,14 @@ github.com/mitchellh/go-homedir v1.0.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrk
github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y=
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
github.com/mitchellh/go-testing-interface v1.0.0/go.mod h1:kRemZodwjscx+RGhAo8eIhFbs2+BFgRtFPeD/KE+zxI=
github.com/mitchellh/go-testing-interface v1.14.1 h1:jrgshOhYAUVNMAJiKbEu7EqAwgJJ2JqpQmpLJOu07cU=
github.com/mitchellh/go-testing-interface v1.14.1/go.mod h1:gfgS7OtZj6MA4U1UrDRp04twqAjfvlZyCfX3sDjEym8=
github.com/mitchellh/gox v0.4.0/go.mod h1:Sd9lOJ0+aimLBi73mGofS1ycjY8lL3uZM3JPS42BGNg=
github.com/mitchellh/iochan v1.0.0/go.mod h1:JwYml1nuB7xOzsp52dPpHFffvOCDupsG0QubkSMEySY=
github.com/mitchellh/mapstructure v0.0.0-20160808181253-ca63d7c062ee/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
github.com/mitchellh/mapstructure v1.1.2 h1:fmNYVwqnSfB9mZU6OS2O6GsXM+wcskZDuKQzvN1EDeE=
github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
github.com/mitchellh/mapstructure v1.4.3 h1:OVowDSCllw/YjdLkam3/sm7wEtOy59d8ndGgCcyj8cs=
github.com/mitchellh/mapstructure v1.4.3/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
github.com/mitchellh/osext v0.0.0-20151018003038-5e2d6d41470f/go.mod h1:OkQIRizQZAeMln+1tSwduZz7+Af5oFlKirV/MSYes2A=
github.com/moby/locker v1.0.1/go.mod h1:S7SDdo5zpBK84bzzVlKr2V0hz+7x9hWbYC/kq7oQppc=
github.com/moby/spdystream v0.2.0 h1:cjW1zVyyoiM0T7b6UoySUFqzXMoqRckQtXwGPiBhOM8=
Expand Down
3 changes: 2 additions & 1 deletion api/http/handler/edgegroups/associated_endpoints.go
Expand Up @@ -2,6 +2,7 @@ package edgegroups

import (
portaineree "github.com/portainer/portainer-ee/api"
"github.com/portainer/portainer-ee/api/internal/endpointutils"
)

type endpointSetType map[portaineree.EndpointID]bool
Expand Down Expand Up @@ -38,7 +39,7 @@ func (handler *Handler) getEndpointsByTags(tagIDs []portaineree.TagID, partialMa

results := []portaineree.EndpointID{}
for _, endpoint := range endpoints {
if _, ok := endpointSet[endpoint.ID]; ok && (endpoint.Type == portaineree.EdgeAgentOnDockerEnvironment || endpoint.Type == portaineree.EdgeAgentOnKubernetesEnvironment) {
if _, ok := endpointSet[endpoint.ID]; ok && endpointutils.IsEdgeEndpoint(&endpoint) {
results = append(results, endpoint.ID)
}
}
Expand Down
13 changes: 7 additions & 6 deletions api/http/handler/edgegroups/edgegroup_create.go
Expand Up @@ -2,6 +2,7 @@ package edgegroups

import (
"errors"
"github.com/portainer/portainer-ee/api/internal/endpointutils"
"net/http"

"github.com/asaskevich/govalidator"
Expand Down Expand Up @@ -49,17 +50,17 @@ func (handler *Handler) edgeGroupCreate(w http.ResponseWriter, r *http.Request)
var payload edgeGroupCreatePayload
err := request.DecodeAndValidateJSONPayload(r, &payload)
if err != nil {
return &httperror.HandlerError{http.StatusBadRequest, "Invalid request payload", err}
return &httperror.HandlerError{StatusCode: http.StatusBadRequest, Message: "Invalid request payload", Err: err}
}

edgeGroups, err := handler.DataStore.EdgeGroup().EdgeGroups()
if err != nil {
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve Edge groups from the database", err}
return &httperror.HandlerError{StatusCode: http.StatusInternalServerError, Message: "Unable to retrieve Edge groups from the database", Err: err}
}

for _, edgeGroup := range edgeGroups {
if edgeGroup.Name == payload.Name {
return &httperror.HandlerError{http.StatusBadRequest, "Edge group name must be unique", errors.New("Edge group name must be unique")}
return &httperror.HandlerError{StatusCode: http.StatusBadRequest, Message: "Edge group name must be unique", Err: errors.New("Edge group name must be unique")}
}
}

Expand All @@ -78,10 +79,10 @@ func (handler *Handler) edgeGroupCreate(w http.ResponseWriter, r *http.Request)
for _, endpointID := range payload.Endpoints {
endpoint, err := handler.DataStore.Endpoint().Endpoint(endpointID)
if err != nil {
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve environment from the database", err}
return &httperror.HandlerError{StatusCode: http.StatusInternalServerError, Message: "Unable to retrieve environment from the database", Err: err}
}

if endpoint.Type == portaineree.EdgeAgentOnDockerEnvironment || endpoint.Type == portaineree.EdgeAgentOnKubernetesEnvironment {
if endpointutils.IsEdgeEndpoint(endpoint) {
endpointIDs = append(endpointIDs, endpoint.ID)
}
}
Expand All @@ -90,7 +91,7 @@ func (handler *Handler) edgeGroupCreate(w http.ResponseWriter, r *http.Request)

err = handler.DataStore.EdgeGroup().Create(edgeGroup)
if err != nil {
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to persist the Edge group inside the database", err}
return &httperror.HandlerError{StatusCode: http.StatusInternalServerError, Message: "Unable to persist the Edge group inside the database", Err: err}
}

return response.JSON(w, edgeGroup)
Expand Down
3 changes: 2 additions & 1 deletion api/http/handler/edgegroups/edgegroup_update.go
Expand Up @@ -2,6 +2,7 @@ package edgegroups

import (
"errors"
"github.com/portainer/portainer-ee/api/internal/endpointutils"
"net/http"

"github.com/asaskevich/govalidator"
Expand Down Expand Up @@ -103,7 +104,7 @@ func (handler *Handler) edgeGroupUpdate(w http.ResponseWriter, r *http.Request)
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve environment from the database", err}
}

if endpoint.Type == portaineree.EdgeAgentOnDockerEnvironment || endpoint.Type == portaineree.EdgeAgentOnKubernetesEnvironment {
if endpointutils.IsEdgeEndpoint(endpoint) {
endpointIDs = append(endpointIDs, endpoint.ID)
}
}
Expand Down
3 changes: 2 additions & 1 deletion api/http/handler/edgejobs/edgejob_create.go
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/portainer/libhttp/request"
"github.com/portainer/libhttp/response"
portaineree "github.com/portainer/portainer-ee/api"
"github.com/portainer/portainer-ee/api/internal/endpointutils"
)

// @id EdgeJobCreate
Expand Down Expand Up @@ -200,7 +201,7 @@ func (handler *Handler) addAndPersistEdgeJob(edgeJob *portaineree.EdgeJob, file
return err
}

if endpoint.Type != portaineree.EdgeAgentOnDockerEnvironment && endpoint.Type != portaineree.EdgeAgentOnKubernetesEnvironment {
if !endpointutils.IsEdgeEndpoint(endpoint) {
delete(edgeJob.Endpoints, ID)
}
}
Expand Down
2 changes: 1 addition & 1 deletion api/http/handler/edgejobs/edgejob_update.go
Expand Up @@ -101,7 +101,7 @@ func (handler *Handler) updateEdgeSchedule(edgeJob *portaineree.EdgeJob, payload
return err
}

if endpoint.Type != portaineree.EdgeAgentOnDockerEnvironment && endpoint.Type != portaineree.EdgeAgentOnKubernetesEnvironment {
if !endpointutils.IsEdgeEndpoint(endpoint) {
continue
}

Expand Down

0 comments on commit 3ca72a2

Please sign in to comment.