Skip to content

Commit

Permalink
add alias column when printing freight with kubectl (akuity#1203)
Browse files Browse the repository at this point in the history
Signed-off-by: Kent <kent.rancourt@gmail.com>
  • Loading branch information
krancour authored Dec 1, 2023
1 parent e2b7b50 commit fc6e5e0
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 10 deletions.
2 changes: 2 additions & 0 deletions api/v1alpha1/freight_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import (

//+kubebuilder:object:root=true
//+kubebuilder:subresource:status
//+kubebuilder:printcolumn:name=Alias,type=string,JSONPath=`.metadata.labels.kargo\.akuity\.io/alias`
//+kubebuilder:printcolumn:name=Age,type=date,JSONPath=`.metadata.creationTimestamp`

// Freight represents a collection of versioned artifacts.
type Freight struct {
Expand Down
2 changes: 2 additions & 0 deletions api/v1alpha1/labels.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ const (
LabelProjectKey = "kargo.akuity.io/project"

LabelTrueValue = "true"

AliasLabelKey = "kargo.akuity.io/alias"
)
9 changes: 8 additions & 1 deletion charts/kargo/crds/kargo.akuity.io_freights.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,14 @@ spec:
singular: freight
scope: Namespaced
versions:
- name: v1alpha1
- additionalPrinterColumns:
- jsonPath: .metadata.labels.kargo\.akuity\.io/alias
name: Alias
type: string
- jsonPath: .metadata.creationTimestamp
name: Age
type: date
name: v1alpha1
schema:
openAPIV3Schema:
description: Freight represents a collection of versioned artifacts.
Expand Down
6 changes: 2 additions & 4 deletions internal/cli/cmd/get/freight.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ import (
v1alpha1 "github.com/akuity/kargo/pkg/api/service/v1alpha1"
)

const aliasLabelKey = "kargo.akuity.com/alias"

func newGetFreightCommand(opt *option.Option) *cobra.Command {
cmd := &cobra.Command{
Use: "freight --project=project [NAME...]",
Expand Down Expand Up @@ -70,7 +68,7 @@ kargo get freight --project=my-project my-freight
fr := typesv1alpha1.FromFreightProto(f)
freightByName[f.GetMetadata().GetName()] = fr
if f.GetMetadata().GetLabels() != nil {
freightByAlias[f.GetMetadata().GetLabels()[aliasLabelKey]] = fr
freightByAlias[f.GetMetadata().GetLabels()[kargoapi.AliasLabelKey]] = fr
}
}
selectedFreight := make(map[string]struct{}, len(names))
Expand Down Expand Up @@ -107,7 +105,7 @@ func newFreightTable(list *metav1.List) *metav1.Table {
freight := item.Object.(*kargoapi.Freight) // nolint: forcetypeassert
var alias string
if freight.Labels != nil {
alias = freight.Labels[aliasLabelKey]
alias = freight.Labels[kargoapi.AliasLabelKey]
}
rows[i] = metav1.TableRow{
Cells: []any{
Expand Down
4 changes: 1 addition & 3 deletions internal/controller/warehouses/aliases.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import (
kargoapi "github.com/akuity/kargo/api/v1alpha1"
)

const aliasLabelKey = "kargo.akuity.com/alias"

func (r *reconciler) getAvailableFreightAlias(
ctx context.Context,
) (string, error) {
Expand All @@ -20,7 +18,7 @@ func (r *reconciler) getAvailableFreightAlias(
if err := r.client.List(
ctx,
&freight,
client.MatchingLabels{aliasLabelKey: alias},
client.MatchingLabels{kargoapi.AliasLabelKey: alias},
); err != nil {
return "", errors.Wrapf(
err,
Expand Down
2 changes: 1 addition & 1 deletion internal/controller/warehouses/warehouses.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ func (r *reconciler) syncWarehouse(
logger.Debug("got latest Freight from repositories")

freight.Labels = map[string]string{}
if freight.Labels[aliasLabelKey], err =
if freight.Labels[kargoapi.AliasLabelKey], err =
r.getAvailableFreightAliasFn(ctx); err != nil {
return status, errors.Wrap(err, "error getting available Freight alias")
}
Expand Down
2 changes: 1 addition & 1 deletion ui/src/features/common/freight-label.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { useEffect, useState } from 'react';

import { Freight } from '@ui/gen/v1alpha1/types_pb';

const ALIAS_LABEL_KEY = 'kargo.akuity.com/alias';
const ALIAS_LABEL_KEY = 'kargo.akuity.io/alias';

export const FreightLabel = ({ freight }: { freight?: Freight }) => {
const [id, setId] = useState<string>('');
Expand Down

0 comments on commit fc6e5e0

Please sign in to comment.