Skip to content

Commit

Permalink
Update Agent Pool CRD & Add Logs
Browse files Browse the repository at this point in the history
  • Loading branch information
sheneska committed Oct 15, 2024
1 parent e6fbc10 commit d06cd5e
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 20 deletions.
16 changes: 13 additions & 3 deletions api/v1alpha2/agentpool_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,19 @@ type AgentDeploymentAutoscalingCooldownPeriod struct {
}

type AgentDeployment struct {
Replicas *int32 `json:"replicas,omitempty"`
Spec *v1.PodSpec `json:"spec,omitempty"`
Labels map[string]string `json:"labels,omitempty"`
Replicas *int32 `json:"replicas,omitempty"`
Spec *v1.PodSpec `json:"spec,omitempty"`

//Labels are intended to specify identifying attributes of objects
//that are meaningful and relevant to users.These are applied to the
//pod template within the AgentDeployment, helping to organize and select
//pods.
//+optional
Labels map[string]string `json:"labels,omitempty"`

//Annotations are used to provide metadata. They are applied to the pod
//template within the AgentDeployment.
//+optional
Annotations map[string]string `json:"annotations,omitempty"`
}

Expand Down
14 changes: 14 additions & 0 deletions api/v1alpha2/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@ spec:
agentDeployment:
description: Agent deployment settings
properties:
annotations:
additionalProperties:
type: string
type: object
labels:
additionalProperties:
type: string
type: object
replicas:
format: int32
type: integer
Expand Down
8 changes: 8 additions & 0 deletions config/crd/bases/app.terraform.io_agentpools.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@ spec:
agentDeployment:
description: Agent deployment settings
properties:
annotations:
additionalProperties:
type: string
type: object
labels:
additionalProperties:
type: string
type: object
replicas:
format: int32
type: integer
Expand Down
10 changes: 0 additions & 10 deletions controllers/agentpool_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,16 +75,6 @@ func (r *AgentPoolReconciler) Reconcile(ctx context.Context, req ctrl.Request) (
}
ap.log.Info("Spec Validation", "msg", "spec is valid")

// if ap.instance.Spec.AgentDeployment != nil {
// if ap.instance.Spec.AgentDeployment.Labels != nil {
// ap.log.Info("Labels available: ", "labels", ap.instance.Spec.AgentDeployment.Labels)
// } else {
// ap.log.Info("Labels available: ", "labels", "There are no labels")
// }
// } else {
// ap.log.Info("There are no labels")
// }

if needToAddFinalizer(&ap.instance, agentPoolFinalizer) {
err := r.addFinalizer(ctx, &ap.instance)
if err != nil {
Expand Down
25 changes: 18 additions & 7 deletions controllers/agentpool_controller_deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const (
poolIDLabel = "agentpool.app.terraform.io/pool-id"
defaultAgentImage = "hashicorp/tfc-agent"
defaultAgentContainerName = "tfc-agent"
DeploymentAnnotations = "agentpool.app.terraform.io/deployment-name"
deploymentAnnotations = "agentpool.app.terraform.io/deployment-name"
)

func (r *AgentPoolReconciler) reconcileAgentDeployment(ctx context.Context, ap *agentPoolInstance) error {
Expand Down Expand Up @@ -226,22 +226,33 @@ func agentPoolDeploymentName(ap *appv1alpha2.AgentPool) string {
}

func agentPoolPodLabels(ap *appv1alpha2.AgentPool) map[string]string {
label := map[string]string{
poolNameLabel: ap.Name,
}

label := map[string]string{}

//Attempting to merge
if ap.Spec.AgentDeployment != nil && ap.Spec.AgentDeployment.Labels != nil {
if len(ap.Spec.AgentDeployment.Labels) > 0 {
for key, value := range ap.Spec.AgentDeployment.Labels {
label[key] = value
}
}

//built in assignment
label[poolNameLabel] = ap.Name

return label
}

func agentDeploymentAnnotations(ap *appv1alpha2.AgentPool) map[string]string {
return map[string]string{
DeploymentAnnotations: ap.Name, //the format, key:value pair

annotations := map[string]string{}

if len(ap.Spec.AgentDeployment.Annotations) > 0 {
for key, value := range ap.Spec.AgentDeployment.Annotations {
annotations[key] = value
}
}

annotations[deploymentAnnotations] = ap.Name

return annotations
}
2 changes: 2 additions & 0 deletions docs/api-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ _Appears in:_
| --- | --- |
| `replicas` _integer_ | |
| `spec` _[PodSpec](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.27/#podspec-v1-core)_ | |
| `labels` _object (keys:string, values:string)_ | |
| `annotations` _object (keys:string, values:string)_ | |


#### AgentDeploymentAutoscaling
Expand Down

0 comments on commit d06cd5e

Please sign in to comment.