Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add alias column when printing freight with kubectl #1203

Merged
merged 4 commits into from
Dec 1, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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`
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once you add any column, you're responsible for all of them, except for Name.


// 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"
)
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