features.go 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. package features
  2. import (
  3. "strconv"
  4. "strings"
  5. "github.com/porter-dev/porter/api/server/handlers/cluster"
  6. "github.com/porter-dev/porter/internal/kubernetes"
  7. )
  8. // isPorterAgentUpdated checks if the agent version is at least the version specified by the major, minor, and patch arguments
  9. func isPorterAgentUpdated(agent *kubernetes.Agent, major, minor, patch int) bool {
  10. res, err := cluster.GetAgentVersionResponse(agent)
  11. if err != nil {
  12. return false
  13. }
  14. image := res.Image
  15. parsed := strings.Split(image, ":")
  16. if len(parsed) != 2 {
  17. return false
  18. }
  19. tag := parsed[1]
  20. if tag == "dev" {
  21. return true
  22. }
  23. if !strings.HasPrefix(tag, "v") {
  24. return false
  25. }
  26. tag = strings.TrimPrefix(tag, "v")
  27. parsedTag := strings.Split(tag, ".")
  28. if len(parsedTag) != 3 {
  29. return false
  30. }
  31. parsedMajor, _ := strconv.Atoi(parsedTag[0])
  32. parsedMinor, _ := strconv.Atoi(parsedTag[1])
  33. parsedPatch, _ := strconv.Atoi(parsedTag[2])
  34. if parsedMajor < major {
  35. return false
  36. }
  37. if parsedMinor < minor {
  38. return false
  39. }
  40. if parsedPatch < patch {
  41. return false
  42. }
  43. return true
  44. }
  45. // Only create the PROGRESSING event if the cluster's agent is updated, because only the updated agent can update the status
  46. // TODO: remove dependence on porter email once we are ready to release this feature
  47. func AreAgentDeployEventsEnabled(email string, agent *kubernetes.Agent) bool {
  48. return isPorterAgentUpdated(agent, 3, 1, 6) && strings.HasSuffix(email, "porter.run")
  49. }