porter_app.go 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887
  1. package client
  2. import (
  3. "context"
  4. "fmt"
  5. "github.com/porter-dev/porter/api/server/handlers/porter_app"
  6. "github.com/porter-dev/porter/internal/models"
  7. appInternal "github.com/porter-dev/porter/internal/porter_app"
  8. "github.com/porter-dev/porter/api/types"
  9. )
  10. func (c *Client) NewGetPorterApp(
  11. ctx context.Context,
  12. projectID, clusterID uint,
  13. appName string,
  14. ) (*types.PorterApp, error) {
  15. resp := &types.PorterApp{}
  16. err := c.getRequest(
  17. fmt.Sprintf(
  18. "/projects/%d/clusters/%d/applications/%s",
  19. projectID, clusterID, appName,
  20. ),
  21. nil,
  22. resp,
  23. )
  24. return resp, err
  25. }
  26. func (c *Client) NewCreatePorterApp(
  27. ctx context.Context,
  28. projectID, clusterID uint,
  29. appName string,
  30. req *types.CreatePorterAppRequest,
  31. ) (*types.PorterApp, error) {
  32. resp := &types.PorterApp{}
  33. err := c.postRequest(
  34. fmt.Sprintf(
  35. "/projects/%d/clusters/%d/applications/%s",
  36. projectID, clusterID, appName,
  37. ),
  38. req,
  39. resp,
  40. )
  41. return resp, err
  42. }
  43. // NewCreateOrUpdatePorterAppEvent will create a porter app event if one does not exist, or else it will update the existing one if an ID is passed in the object
  44. func (c *Client) NewCreateOrUpdatePorterAppEvent(
  45. ctx context.Context,
  46. projectID, clusterID uint,
  47. appName string,
  48. req *types.CreateOrUpdatePorterAppEventRequest,
  49. ) (types.PorterAppEvent, error) {
  50. resp := &types.PorterAppEvent{}
  51. err := c.postRequest(
  52. fmt.Sprintf(
  53. "/projects/%d/clusters/%d/applications/%s/events",
  54. projectID, clusterID, appName,
  55. ),
  56. req,
  57. resp,
  58. )
  59. return *resp, err
  60. }
  61. // TODO: remove these functions once they are no longer called (check telemetry)
  62. func (c *Client) GetPorterApp(
  63. ctx context.Context,
  64. projectID, clusterID uint,
  65. stackName string,
  66. ) (*types.PorterApp, error) {
  67. resp := &types.PorterApp{}
  68. err := c.getRequest(
  69. fmt.Sprintf(
  70. "/projects/%d/clusters/%d/stacks/%s",
  71. projectID, clusterID, stackName,
  72. ),
  73. nil,
  74. resp,
  75. )
  76. return resp, err
  77. }
  78. func (c *Client) CreatePorterApp(
  79. ctx context.Context,
  80. projectID, clusterID uint,
  81. name string,
  82. req *types.CreatePorterAppRequest,
  83. ) (*types.PorterApp, error) {
  84. resp := &types.PorterApp{}
  85. err := c.postRequest(
  86. fmt.Sprintf(
  87. "/projects/%d/clusters/%d/stacks/%s",
  88. projectID, clusterID, name,
  89. ),
  90. req,
  91. resp,
  92. )
  93. return resp, err
  94. }
  95. // CreateOrUpdatePorterAppEvent will create a porter app event if one does not exist, or else it will update the existing one if an ID is passed in the object
  96. func (c *Client) CreateOrUpdatePorterAppEvent(
  97. ctx context.Context,
  98. projectID, clusterID uint,
  99. name string,
  100. req *types.CreateOrUpdatePorterAppEventRequest,
  101. ) (types.PorterAppEvent, error) {
  102. resp := &types.PorterAppEvent{}
  103. err := c.postRequest(
  104. fmt.Sprintf(
  105. "/projects/%d/clusters/%d/stacks/%s/events",
  106. projectID, clusterID, name,
  107. ),
  108. req,
  109. resp,
  110. )
  111. return *resp, err
  112. }
  113. // ListEnvGroups (List all Env Groups for a given cluster)
  114. func (c *Client) ListEnvGroups(
  115. ctx context.Context,
  116. projectID, clusterID uint,
  117. ) (types.ListEnvironmentGroupsResponse, error) {
  118. resp := &types.ListEnvironmentGroupsResponse{}
  119. err := c.getRequest(
  120. fmt.Sprintf(
  121. "/projects/%d/clusters/%d/environment-groups",
  122. projectID, clusterID,
  123. ),
  124. nil,
  125. resp,
  126. )
  127. return *resp, err
  128. }
  129. // ParseYAML takes in a base64 encoded porter yaml and returns an app proto
  130. func (c *Client) ParseYAML(
  131. ctx context.Context,
  132. projectID, clusterID uint,
  133. b64Yaml string,
  134. appName string,
  135. ) (*porter_app.ParsePorterYAMLToProtoResponse, error) {
  136. resp := &porter_app.ParsePorterYAMLToProtoResponse{}
  137. req := &porter_app.ParsePorterYAMLToProtoRequest{
  138. B64Yaml: b64Yaml,
  139. AppName: appName,
  140. }
  141. err := c.postRequest(
  142. fmt.Sprintf(
  143. "/projects/%d/clusters/%d/apps/parse",
  144. projectID, clusterID,
  145. ),
  146. req,
  147. resp,
  148. )
  149. return resp, err
  150. }
  151. // GetAppManifests returns the manifests for a given app based on the latest successful app revision
  152. func (c *Client) GetAppManifests(
  153. ctx context.Context,
  154. projectID, clusterID uint,
  155. appName string,
  156. ) (*porter_app.AppManifestsResponse, error) {
  157. resp := &porter_app.AppManifestsResponse{}
  158. err := c.getRequest(
  159. fmt.Sprintf(
  160. "/projects/%d/clusters/%d/apps/%s/manifests",
  161. projectID, clusterID, appName,
  162. ),
  163. nil,
  164. resp,
  165. )
  166. return resp, err
  167. }
  168. // ValidatePorterAppInput is the input struct to ValidatePorterApp
  169. type ValidatePorterAppInput struct {
  170. ProjectID uint
  171. ClusterID uint
  172. AppName string
  173. Base64AppProto string
  174. Base64AppOverrides string
  175. DeploymentTarget string
  176. CommitSHA string
  177. ImageTagOverride string
  178. }
  179. // ValidatePorterApp takes in a base64 encoded app definition that is potentially partial and returns a complete definition
  180. // using any previous app revisions and defaults
  181. func (c *Client) ValidatePorterApp(
  182. ctx context.Context,
  183. inp ValidatePorterAppInput,
  184. ) (*porter_app.ValidatePorterAppResponse, error) {
  185. resp := &porter_app.ValidatePorterAppResponse{}
  186. req := &porter_app.ValidatePorterAppRequest{
  187. AppName: inp.AppName,
  188. Base64AppProto: inp.Base64AppProto,
  189. Base64AppOverrides: inp.Base64AppOverrides,
  190. DeploymentTargetId: inp.DeploymentTarget,
  191. CommitSHA: inp.CommitSHA,
  192. ImageTagOverride: inp.ImageTagOverride,
  193. }
  194. err := c.postRequest(
  195. fmt.Sprintf(
  196. "/projects/%d/clusters/%d/apps/validate",
  197. inp.ProjectID, inp.ClusterID,
  198. ),
  199. req,
  200. resp,
  201. )
  202. return resp, err
  203. }
  204. // ApplyPorterAppInput is the input struct to ApplyPorterApp
  205. type ApplyPorterAppInput struct {
  206. ProjectID uint
  207. ClusterID uint
  208. Base64AppProto string
  209. DeploymentTarget string
  210. AppRevisionID string
  211. ForceBuild bool
  212. Variables map[string]string
  213. Secrets map[string]string
  214. HardEnvUpdate bool
  215. }
  216. // ApplyPorterApp takes in a base64 encoded app definition and applies it to the cluster
  217. func (c *Client) ApplyPorterApp(
  218. ctx context.Context,
  219. inp ApplyPorterAppInput,
  220. ) (*porter_app.ApplyPorterAppResponse, error) {
  221. resp := &porter_app.ApplyPorterAppResponse{}
  222. req := &porter_app.ApplyPorterAppRequest{
  223. Base64AppProto: inp.Base64AppProto,
  224. DeploymentTargetId: inp.DeploymentTarget,
  225. AppRevisionID: inp.AppRevisionID,
  226. ForceBuild: inp.ForceBuild,
  227. Variables: inp.Variables,
  228. Secrets: inp.Secrets,
  229. HardEnvUpdate: inp.HardEnvUpdate,
  230. }
  231. err := c.postRequest(
  232. fmt.Sprintf(
  233. "/projects/%d/clusters/%d/apps/apply",
  234. inp.ProjectID, inp.ClusterID,
  235. ),
  236. req,
  237. resp,
  238. postRequestOpts{
  239. retryCount: 3,
  240. onlyRetry500: true,
  241. },
  242. )
  243. return resp, err
  244. }
  245. // UpdateAppInput is the input struct to UpdateApp
  246. type UpdateAppInput struct {
  247. ProjectID uint
  248. ClusterID uint
  249. Name string
  250. ImageTagOverride string
  251. GitSource porter_app.GitSource
  252. DeploymentTargetId string
  253. CommitSHA string
  254. AppRevisionID string
  255. Base64AppProto string
  256. Base64PorterYAML string
  257. IsEnvOverride bool
  258. WithPredeploy bool
  259. }
  260. // UpdateApp updates a porter app
  261. func (c *Client) UpdateApp(
  262. ctx context.Context,
  263. inp UpdateAppInput,
  264. ) (*porter_app.UpdateAppResponse, error) {
  265. resp := &porter_app.UpdateAppResponse{}
  266. req := &porter_app.UpdateAppRequest{
  267. Name: inp.Name,
  268. GitSource: inp.GitSource,
  269. DeploymentTargetId: inp.DeploymentTargetId,
  270. CommitSHA: inp.CommitSHA,
  271. ImageTagOverride: inp.ImageTagOverride,
  272. AppRevisionID: inp.AppRevisionID,
  273. Base64AppProto: inp.Base64AppProto,
  274. Base64PorterYAML: inp.Base64PorterYAML,
  275. IsEnvOverride: inp.IsEnvOverride,
  276. WithPredeploy: inp.WithPredeploy,
  277. }
  278. err := c.postRequest(
  279. fmt.Sprintf(
  280. "/projects/%d/clusters/%d/apps/update",
  281. inp.ProjectID, inp.ClusterID,
  282. ),
  283. req,
  284. resp,
  285. )
  286. return resp, err
  287. }
  288. // DefaultDeploymentTarget returns the default deployment target for a given project and cluster
  289. func (c *Client) DefaultDeploymentTarget(
  290. ctx context.Context,
  291. projectID, clusterID uint,
  292. ) (*porter_app.DefaultDeploymentTargetResponse, error) {
  293. resp := &porter_app.DefaultDeploymentTargetResponse{}
  294. req := &porter_app.DefaultDeploymentTargetRequest{}
  295. err := c.getRequest(
  296. fmt.Sprintf(
  297. "/projects/%d/clusters/%d/default-deployment-target",
  298. projectID, clusterID,
  299. ),
  300. req,
  301. resp,
  302. )
  303. return resp, err
  304. }
  305. // CurrentAppRevisionInput is the input struct to CurrentAppRevision
  306. type CurrentAppRevisionInput struct {
  307. ProjectID uint
  308. ClusterID uint
  309. AppName string
  310. // DeploymentTargetName is the name of the deployment target to get the current app revision for. One of this or DeploymentTargetID must be set.
  311. DeploymentTargetName string
  312. // DeploymentTargetID is the id of the deployment target to get the current app revision for. One of this or DeploymentTargetName must be set.
  313. DeploymentTargetID string
  314. }
  315. // CurrentAppRevision returns the currently deployed app revision for a given project, app name and deployment target
  316. func (c *Client) CurrentAppRevision(
  317. ctx context.Context,
  318. input CurrentAppRevisionInput,
  319. ) (*porter_app.LatestAppRevisionResponse, error) {
  320. resp := &porter_app.LatestAppRevisionResponse{}
  321. req := &porter_app.LatestAppRevisionRequest{
  322. DeploymentTargetName: input.DeploymentTargetName,
  323. DeploymentTargetID: input.DeploymentTargetID,
  324. }
  325. err := c.getRequest(
  326. fmt.Sprintf(
  327. "/projects/%d/clusters/%d/apps/%s/latest",
  328. input.ProjectID, input.ClusterID, input.AppName,
  329. ),
  330. req,
  331. resp,
  332. )
  333. return resp, err
  334. }
  335. // CreatePorterAppDBEntryInput is the input struct to CreatePorterAppDBEntry
  336. type CreatePorterAppDBEntryInput struct {
  337. AppName string
  338. GitRepoName string
  339. GitRepoID uint
  340. GitBranch string
  341. ImageRepository string
  342. PorterYamlPath string
  343. ImageTag string
  344. Local bool
  345. DeploymentTargetID string
  346. }
  347. // CreatePorterAppDBEntry creates an entry in the porter app
  348. func (c *Client) CreatePorterAppDBEntry(
  349. ctx context.Context,
  350. projectID uint, clusterID uint,
  351. inp CreatePorterAppDBEntryInput,
  352. ) error {
  353. var sourceType appInternal.SourceType
  354. var image *appInternal.Image
  355. if inp.Local {
  356. sourceType = appInternal.SourceType_Local
  357. }
  358. if inp.GitRepoName != "" {
  359. sourceType = appInternal.SourceType_Github
  360. }
  361. if inp.ImageRepository != "" {
  362. sourceType = appInternal.SourceType_DockerRegistry
  363. image = &appInternal.Image{
  364. Repository: inp.ImageRepository,
  365. Tag: inp.ImageTag,
  366. }
  367. }
  368. req := &porter_app.CreateAppRequest{
  369. Name: inp.AppName,
  370. SourceType: sourceType,
  371. GitSource: porter_app.GitSource{
  372. GitBranch: inp.GitBranch,
  373. GitRepoName: inp.GitRepoName,
  374. GitRepoID: inp.GitRepoID,
  375. },
  376. Image: image,
  377. PorterYamlPath: inp.PorterYamlPath,
  378. DeploymentTargetID: inp.DeploymentTargetID,
  379. }
  380. err := c.postRequest(
  381. fmt.Sprintf(
  382. "/projects/%d/clusters/%d/apps/create",
  383. projectID, clusterID,
  384. ),
  385. req,
  386. &types.PorterApp{},
  387. )
  388. return err
  389. }
  390. // CreateSubdomain returns a subdomain for a given service that point to the ingress-nginx service in the cluster
  391. func (c *Client) CreateSubdomain(
  392. ctx context.Context,
  393. projectID uint, clusterID uint,
  394. appName string, serviceName string,
  395. ) (*porter_app.CreateSubdomainResponse, error) {
  396. resp := &porter_app.CreateSubdomainResponse{}
  397. req := &porter_app.CreateSubdomainRequest{
  398. ServiceName: serviceName,
  399. }
  400. err := c.postRequest(
  401. fmt.Sprintf(
  402. "/projects/%d/clusters/%d/apps/%s/subdomain",
  403. projectID, clusterID, appName,
  404. ),
  405. req,
  406. resp,
  407. )
  408. return resp, err
  409. }
  410. // PredeployStatus checks the current status of a predeploy job for an app revision
  411. func (c *Client) PredeployStatus(
  412. ctx context.Context,
  413. projectID uint, clusterID uint,
  414. appName string, appRevisionId string,
  415. ) (*porter_app.PredeployStatusResponse, error) {
  416. resp := &porter_app.PredeployStatusResponse{}
  417. err := c.getRequest(
  418. fmt.Sprintf(
  419. "/projects/%d/clusters/%d/apps/%s/%s/predeploy-status",
  420. projectID, clusterID, appName, appRevisionId,
  421. ),
  422. nil,
  423. resp,
  424. )
  425. if resp.Status == "" {
  426. return nil, fmt.Errorf("no predeploy status found")
  427. }
  428. return resp, err
  429. }
  430. // GetRevision returns an app revision
  431. func (c *Client) GetRevision(
  432. ctx context.Context,
  433. projectID uint, clusterID uint,
  434. appName string, appRevisionId string,
  435. ) (*porter_app.GetAppRevisionResponse, error) {
  436. resp := &porter_app.GetAppRevisionResponse{}
  437. err := c.getRequest(
  438. fmt.Sprintf(
  439. "/projects/%d/clusters/%d/apps/%s/revisions/%s",
  440. projectID, clusterID, appName, appRevisionId,
  441. ),
  442. nil,
  443. resp,
  444. )
  445. return resp, err
  446. }
  447. // GetRevisionStatus returns the status of an app revision
  448. func (c *Client) GetRevisionStatus(
  449. ctx context.Context,
  450. projectID uint, clusterID uint,
  451. appName string, appRevisionId string,
  452. ) (*porter_app.GetAppRevisionStatusResponse, error) {
  453. resp := &porter_app.GetAppRevisionStatusResponse{}
  454. err := c.getRequest(
  455. fmt.Sprintf(
  456. "/projects/%d/clusters/%d/apps/%s/revisions/%s/status",
  457. projectID, clusterID, appName, appRevisionId,
  458. ),
  459. nil,
  460. resp,
  461. )
  462. return resp, err
  463. }
  464. // UpdateRevisionStatus updates the status of an app revision
  465. func (c *Client) UpdateRevisionStatus(
  466. ctx context.Context,
  467. projectID uint, clusterID uint,
  468. appName string, appRevisionId string,
  469. status models.AppRevisionStatus,
  470. ) (*porter_app.UpdateAppRevisionStatusResponse, error) {
  471. resp := &porter_app.UpdateAppRevisionStatusResponse{}
  472. req := &porter_app.UpdateAppRevisionStatusRequest{
  473. Status: status,
  474. }
  475. err := c.postRequest(
  476. fmt.Sprintf(
  477. "/projects/%d/clusters/%d/apps/%s/revisions/%s",
  478. projectID, clusterID, appName, appRevisionId,
  479. ),
  480. req,
  481. resp,
  482. )
  483. return resp, err
  484. }
  485. // GetBuildEnv returns the build environment for a given app proto
  486. func (c *Client) GetBuildEnv(
  487. ctx context.Context,
  488. projectID uint, clusterID uint,
  489. appName string, appRevisionId string,
  490. ) (*porter_app.GetBuildEnvResponse, error) {
  491. resp := &porter_app.GetBuildEnvResponse{}
  492. err := c.getRequest(
  493. fmt.Sprintf(
  494. "/projects/%d/clusters/%d/apps/%s/revisions/%s/build-env",
  495. projectID, clusterID, appName, appRevisionId,
  496. ),
  497. nil,
  498. resp,
  499. )
  500. return resp, err
  501. }
  502. // GetAppEnvVariables returns all env variables for a given app
  503. func (c *Client) GetAppEnvVariables(
  504. ctx context.Context,
  505. projectID uint, clusterID uint,
  506. appName string,
  507. ) (*porter_app.AppEnvVariablesResponse, error) {
  508. resp := &porter_app.AppEnvVariablesResponse{}
  509. req := &porter_app.AppEnvVariablesRequest{}
  510. err := c.getRequest(
  511. fmt.Sprintf(
  512. "/projects/%d/clusters/%d/apps/%s/env-variables",
  513. projectID, clusterID, appName,
  514. ),
  515. req,
  516. resp,
  517. )
  518. return resp, err
  519. }
  520. // GetBuildFromRevision returns the build environment for a given app proto
  521. func (c *Client) GetBuildFromRevision(
  522. ctx context.Context,
  523. projectID uint, clusterID uint,
  524. appName string, appRevisionId string,
  525. ) (*porter_app.GetBuildFromRevisionResponse, error) {
  526. resp := &porter_app.GetBuildFromRevisionResponse{}
  527. err := c.getRequest(
  528. fmt.Sprintf(
  529. "/projects/%d/clusters/%d/apps/%s/revisions/%s/build",
  530. projectID, clusterID, appName, appRevisionId,
  531. ),
  532. nil,
  533. resp,
  534. )
  535. return resp, err
  536. }
  537. // ReportRevisionStatusInput is the input struct to ReportRevisionStatus
  538. type ReportRevisionStatusInput struct {
  539. ProjectID uint
  540. ClusterID uint
  541. AppName string
  542. AppRevisionID string
  543. PRNumber int
  544. CommitSHA string
  545. }
  546. // ReportRevisionStatus reports the status of an app revision to external services
  547. func (c *Client) ReportRevisionStatus(
  548. ctx context.Context,
  549. inp ReportRevisionStatusInput,
  550. ) (*porter_app.ReportRevisionStatusResponse, error) {
  551. resp := &porter_app.ReportRevisionStatusResponse{}
  552. req := &porter_app.ReportRevisionStatusRequest{
  553. PRNumber: inp.PRNumber,
  554. CommitSHA: inp.CommitSHA,
  555. }
  556. err := c.postRequest(
  557. fmt.Sprintf(
  558. "/projects/%d/clusters/%d/apps/%s/revisions/%s/status",
  559. inp.ProjectID, inp.ClusterID, inp.AppName, inp.AppRevisionID,
  560. ),
  561. req,
  562. resp,
  563. )
  564. return resp, err
  565. }
  566. // CreateOrUpdateAppEnvironment updates the app environment group and creates it if it doesn't exist
  567. func (c *Client) CreateOrUpdateAppEnvironment(
  568. ctx context.Context,
  569. projectID uint, clusterID uint,
  570. appName string,
  571. deploymentTargetID string,
  572. variables map[string]string,
  573. secrets map[string]string,
  574. Base64AppProto string,
  575. ) (*porter_app.UpdateAppEnvironmentResponse, error) {
  576. resp := &porter_app.UpdateAppEnvironmentResponse{}
  577. req := &porter_app.UpdateAppEnvironmentRequest{
  578. DeploymentTargetID: deploymentTargetID,
  579. Variables: variables,
  580. Secrets: secrets,
  581. HardUpdate: false,
  582. Base64AppProto: Base64AppProto,
  583. }
  584. err := c.postRequest(
  585. fmt.Sprintf(
  586. "/projects/%d/clusters/%d/apps/%s/update-environment",
  587. projectID, clusterID, appName,
  588. ),
  589. req,
  590. resp,
  591. )
  592. return resp, err
  593. }
  594. // PorterYamlV2Pods gets all pods for a given deployment target id and app name
  595. func (c *Client) PorterYamlV2Pods(
  596. ctx context.Context,
  597. projectID, clusterID uint,
  598. porterAppName string,
  599. deploymentTargetName string,
  600. ) (*types.GetReleaseAllPodsResponse, error) {
  601. req := &porter_app.PodStatusRequest{
  602. DeploymentTargetName: deploymentTargetName,
  603. }
  604. resp := &types.GetReleaseAllPodsResponse{}
  605. err := c.getRequest(
  606. fmt.Sprintf(
  607. "/projects/%d/clusters/%d/apps/%s/pods",
  608. projectID, clusterID,
  609. porterAppName,
  610. ),
  611. req,
  612. resp,
  613. )
  614. return resp, err
  615. }
  616. // UpdateImage updates the image for a porter app (porter yaml v2 only)
  617. func (c *Client) UpdateImage(
  618. ctx context.Context,
  619. projectID, clusterID uint,
  620. appName, deploymentTargetName, tag string,
  621. ) (*porter_app.UpdateImageResponse, error) {
  622. req := &porter_app.UpdateImageRequest{
  623. Tag: tag,
  624. DeploymentTargetName: deploymentTargetName,
  625. }
  626. resp := &porter_app.UpdateImageResponse{}
  627. err := c.postRequest(
  628. fmt.Sprintf(
  629. "/projects/%d/clusters/%d/apps/%s/update-image",
  630. projectID, clusterID, appName,
  631. ),
  632. &req,
  633. resp,
  634. )
  635. return resp, err
  636. }
  637. // ListAppRevisions lists the last ten app revisions for a given app
  638. func (c *Client) ListAppRevisions(
  639. ctx context.Context,
  640. projectID, clusterID uint,
  641. appName string,
  642. deploymentTargetID string,
  643. ) (*porter_app.ListAppRevisionsResponse, error) {
  644. resp := &porter_app.ListAppRevisionsResponse{}
  645. req := &porter_app.ListAppRevisionsRequest{
  646. DeploymentTargetID: deploymentTargetID,
  647. }
  648. err := c.getRequest(
  649. fmt.Sprintf(
  650. "/projects/%d/clusters/%d/apps/%s/revisions",
  651. projectID, clusterID,
  652. appName,
  653. ),
  654. req,
  655. resp,
  656. )
  657. return resp, err
  658. }
  659. // RollbackRevision reverts an app to a previous revision
  660. func (c *Client) RollbackRevision(
  661. ctx context.Context,
  662. projectID, clusterID uint,
  663. appName string,
  664. deploymentTargetName string,
  665. ) (*porter_app.RollbackAppRevisionResponse, error) {
  666. resp := &porter_app.RollbackAppRevisionResponse{}
  667. req := &porter_app.RollbackAppRevisionRequest{
  668. DeploymentTargetName: deploymentTargetName,
  669. }
  670. err := c.postRequest(
  671. fmt.Sprintf(
  672. "/projects/%d/clusters/%d/apps/%s/rollback",
  673. projectID, clusterID,
  674. appName,
  675. ),
  676. req,
  677. resp,
  678. )
  679. return resp, err
  680. }
  681. // UseNewApplyLogic checks whether the CLI should use the new apply logic
  682. func (c *Client) UseNewApplyLogic(
  683. ctx context.Context,
  684. projectID, clusterID uint,
  685. ) (*porter_app.UseNewApplyLogicResponse, error) {
  686. resp := &porter_app.UseNewApplyLogicResponse{}
  687. req := &porter_app.UseNewApplyLogicRequest{}
  688. err := c.getRequest(
  689. fmt.Sprintf(
  690. "/projects/%d/clusters/%d/apps/use-new-apply-logic",
  691. projectID, clusterID,
  692. ),
  693. req,
  694. resp,
  695. )
  696. return resp, err
  697. }
  698. // RunAppJob runs a job for an app
  699. func (c *Client) RunAppJob(
  700. ctx context.Context,
  701. projectID, clusterID uint,
  702. appName string, jobName string,
  703. deploymentTargetName string,
  704. ) (*porter_app.RunAppJobResponse, error) {
  705. resp := &porter_app.RunAppJobResponse{}
  706. req := &porter_app.RunAppJobRequest{
  707. ServiceName: jobName,
  708. DeploymentTargetName: deploymentTargetName,
  709. }
  710. err := c.postRequest(
  711. fmt.Sprintf(
  712. "/projects/%d/clusters/%d/apps/%s/run",
  713. projectID, clusterID,
  714. appName,
  715. ),
  716. req,
  717. resp,
  718. )
  719. return resp, err
  720. }
  721. // RunAppJobStatusInput contains all the information necessary to check the status of a job
  722. type RunAppJobStatusInput struct {
  723. // AppName is the name of the app associated with the job
  724. AppName string
  725. // Cluster is the id of the cluster against which to retrieve a helm agent for
  726. ClusterID uint
  727. // DeploymentTargetName is the id of the deployment target the job was run against
  728. DeploymentTargetName string
  729. // ServiceName is the name of the app service that was triggered
  730. ServiceName string
  731. // JobRunID is the UID returned from the /apps/{porter_app_name}/run endpoint
  732. JobRunID string
  733. // ProjectID is the project in which the cluster exists
  734. ProjectID uint
  735. }
  736. // RunAppJobStatus gets the status for a job app run
  737. func (c *Client) RunAppJobStatus(
  738. ctx context.Context,
  739. input RunAppJobStatusInput,
  740. ) (*porter_app.AppJobRunStatusResponse, error) {
  741. resp := &porter_app.AppJobRunStatusResponse{}
  742. req := &porter_app.AppJobRunStatusRequest{
  743. DeploymentTargetName: input.DeploymentTargetName,
  744. JobRunID: input.JobRunID,
  745. ServiceName: input.ServiceName,
  746. }
  747. err := c.getRequest(
  748. fmt.Sprintf(
  749. "/projects/%d/clusters/%d/apps/%s/run-status",
  750. input.ProjectID, input.ClusterID,
  751. input.AppName,
  752. ),
  753. req,
  754. resp,
  755. )
  756. return resp, err
  757. }