deployment_target.go 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. package models
  2. import (
  3. "github.com/google/uuid"
  4. "github.com/porter-dev/porter/api/types"
  5. "gorm.io/gorm"
  6. )
  7. // DeploymentTargetSelectorType is the type of selector for a deployment target
  8. type DeploymentTargetSelectorType string
  9. const (
  10. // DeploymentTargetSelectorType_Namespace indicates that the selector is a namespace
  11. DeploymentTargetSelectorType_Namespace DeploymentTargetSelectorType = "NAMESPACE"
  12. )
  13. // DeploymentTarget represents a deployment target on a given cluster
  14. type DeploymentTarget struct {
  15. gorm.Model
  16. // ID is a UUID for the Revision
  17. ID uuid.UUID `gorm:"type:uuid;primaryKey" json:"id"`
  18. // ClusterID is the ID of the cluster that is being targeted.
  19. ClusterID int `json:"cluster_id"`
  20. // ProjectID is the ID of the project that the target belongs to.
  21. ProjectID int `json:"project_id"`
  22. // Selector is the identifier to target.
  23. Selector string `json:"selector"`
  24. // SelectorType is the kind of selector (i.e. NAMESPACE or LABEL).
  25. SelectorType DeploymentTargetSelectorType `json:"selector_type"`
  26. // Preview is a boolean indicating whether this target is a preview target.
  27. Preview bool `gorm:"default:false" json:"preview"`
  28. }
  29. // ToDeploymentTargetType generates an external types.PorterApp to be shared over REST
  30. func (d *DeploymentTarget) ToDeploymentTargetType() *types.DeploymentTarget {
  31. return &types.DeploymentTarget{
  32. ID: d.ID,
  33. ProjectID: uint(d.ProjectID),
  34. ClusterID: uint(d.ClusterID),
  35. Selector: d.Selector,
  36. SelectorType: string(d.SelectorType),
  37. CreatedAt: d.CreatedAt,
  38. UpdatedAt: d.UpdatedAt,
  39. }
  40. }