deployment_target.go 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. // VanityName is a human-readable name for the deployment target. It will be unique within a project once all existing deployment targets have been backfilled (tracking: POR-1991)
  23. VanityName string `json:"vanity_name" gorm:"default:''"`
  24. // Selector is the identifier to target.
  25. Selector string `json:"selector"`
  26. // SelectorType is the kind of selector (i.e. NAMESPACE or LABEL).
  27. SelectorType DeploymentTargetSelectorType `json:"selector_type"`
  28. // Preview is a boolean indicating whether this target is a preview target.
  29. Preview bool `gorm:"default:false" json:"preview"`
  30. // Metadata is a JSONB column that stores arbitrary metadata about the deployment target
  31. Metadata JSONB `json:"metadata" sql:"type:jsonb" gorm:"type:jsonb;default:'{}'"`
  32. }
  33. // ToDeploymentTargetType generates an external types.PorterApp to be shared over REST
  34. func (d *DeploymentTarget) ToDeploymentTargetType() *types.DeploymentTarget {
  35. return &types.DeploymentTarget{
  36. ID: d.ID,
  37. ProjectID: uint(d.ProjectID),
  38. ClusterID: uint(d.ClusterID),
  39. Selector: d.Selector,
  40. SelectorType: string(d.SelectorType),
  41. CreatedAt: d.CreatedAt,
  42. UpdatedAt: d.UpdatedAt,
  43. }
  44. }