Skip to content
This repository was archived by the owner on May 18, 2026. It is now read-only.

Commit 7d4df0e

Browse files
authored
feat: add new command cluster-supply-chain get (#149)
- gets the details of cluster supply chain selectors in the spec - Update docs - Bold the selector heading Signed-off-by: Shash Reddy <snagarajared@vmware.com>
1 parent 9fe6667 commit 7d4df0e

15 files changed

Lines changed: 903 additions & 12 deletions
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
apiVersion: carto.run/v1alpha1
2+
kind: ClusterSupplyChain
3+
metadata:
4+
name: ci-test
5+
spec:
6+
params:
7+
- default: main
8+
name: gitops_branch
9+
resources:
10+
- name: source-provider
11+
params:
12+
- name: serviceAccount
13+
value: default
14+
templateRef:
15+
kind: ClusterSourceTemplate
16+
name: test
17+
selector:
18+
apps.tanzu.vmware.com/workload-type: web
19+
selectorMatchExpressions:
20+
- {key: name, operator: In, values: [payroll, web]}
21+
selectorMatchFields:
22+
- {key: spec.params, operator: Exists}

.github/workflows/ci.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,12 @@ jobs:
165165
echo "##[group]Update workload"
166166
tanzu apps workload update petclinic --label cli.ci/new-label=true --yes
167167
echo "##[endgroup]"
168+
echo "##[group]Apply clustersupplychain"
169+
kubectl apply -f ./.github/samples/clustersupplychain.yaml
170+
echo "##[endgroup]"
171+
echo "##[group]Get cluster-supply-chain"
172+
tanzu apps cluster-supply-chain get ci-test
173+
echo "##[endgroup]"
168174
- name: Collect diagnostics
169175
run: |
170176
echo "##[group]Static Pod"

acceptance/vendor/cartographer/config/crd/bases/carto.run_clustersupplychains.yaml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,44 @@ spec:
140140
additionalProperties:
141141
type: string
142142
type: object
143+
selectorMatchExpressions:
144+
items:
145+
properties:
146+
key:
147+
type: string
148+
operator:
149+
type: string
150+
values:
151+
items:
152+
type: string
153+
type: array
154+
required:
155+
- key
156+
- operator
157+
type: object
158+
type: array
159+
selectorMatchFields:
160+
items:
161+
properties:
162+
key:
163+
minLength: 1
164+
type: string
165+
operator:
166+
enum:
167+
- In
168+
- NotIn
169+
- Exists
170+
- DoesNotExist
171+
type: string
172+
values:
173+
items:
174+
type: string
175+
type: array
176+
required:
177+
- key
178+
- operator
179+
type: object
180+
type: array
143181
serviceAccountRef:
144182
properties:
145183
name:

docs/command-reference/tanzu_apps_cluster-supply-chain.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,6 @@ patterns for building and configuring workloads
2020
### SEE ALSO
2121

2222
* [tanzu apps](tanzu_apps.md) - Applications on Kubernetes
23+
* [tanzu apps cluster-supply-chain get](tanzu_apps_cluster-supply-chain_get.md) - Get details from a cluster supply chain
2324
* [tanzu apps cluster-supply-chain list](tanzu_apps_cluster-supply-chain_list.md) - table listing of cluster supply chains
2425

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
## tanzu apps cluster-supply-chain get
2+
3+
Get details from a cluster supply chain
4+
5+
### Synopsis
6+
7+
Get details from a cluster supply chain
8+
9+
```
10+
tanzu apps cluster-supply-chain get <name> [flags]
11+
```
12+
13+
### Examples
14+
15+
```
16+
tanzu apps cluster-supply-chain get
17+
```
18+
19+
### Options
20+
21+
```
22+
-h, --help help for get
23+
```
24+
25+
### Options inherited from parent commands
26+
27+
```
28+
--context name name of the kubeconfig context to use (default is current-context defined by kubeconfig)
29+
--kubeconfig file kubeconfig file (default is $HOME/.kube/config)
30+
--no-color disable color output in terminals
31+
-v, --verbose int32 number for the log level verbosity (default 1)
32+
```
33+
34+
### SEE ALSO
35+
36+
* [tanzu apps cluster-supply-chain](tanzu_apps_cluster-supply-chain.md) - patterns for building and configuring workloads
37+

pkg/apis/cartographer/v1alpha1/cluster_supply_chain.go

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,23 @@ type ClusterSupplyChain struct {
4444
}
4545

4646
type SupplyChainSpec struct {
47-
Resources []SupplyChainResource `json:"resources"`
48-
Selector map[string]string `json:"selector"`
49-
Params []DelegatableParam `json:"params,omitempty"`
50-
ServiceAccountRef ServiceAccountRef `json:"serviceAccountRef,omitempty"`
47+
Resources []SupplyChainResource `json:"resources"`
48+
Params []DelegatableParam `json:"params,omitempty"`
49+
ServiceAccountRef ServiceAccountRef `json:"serviceAccountRef,omitempty"`
50+
Selector map[string]string `json:"selector,omitempty"`
51+
SelectorMatchExpressions []metav1.LabelSelectorRequirement `json:"selectorMatchExpressions,omitempty"`
52+
SelectorMatchFields []FieldSelectorRequirement `json:"selectorMatchFields,omitempty"`
53+
}
54+
55+
type FieldSelectorOperator string
56+
57+
type FieldSelectorRequirement struct {
58+
// +kubebuilder:validation:MinLength=1
59+
Key string `json:"key"`
60+
// +kubebuilder:validation:Enum=In;NotIn;Exists;DoesNotExist
61+
Operator FieldSelectorOperator `json:"operator"`
62+
// the values array must be empty.
63+
Values []string `json:"values,omitempty"`
5164
}
5265

5366
type SupplyChainResource struct {

pkg/apis/cartographer/v1alpha1/zz_generated.deepcopy.go

Lines changed: 38 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/commands/clustersupplychain.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ func NewClusterSupplyChainCommand(ctx context.Context, c *cli.Config) *cobra.Com
3535
}
3636

3737
cmd.AddCommand(NewClusterSupplyChainListCommand(ctx, c))
38+
cmd.AddCommand(NewClusterSupplyChainGetCommand(ctx, c))
3839

3940
return cmd
4041
}
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
/*
2+
Copyright 2022 VMware, Inc.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package commands
18+
19+
import (
20+
"context"
21+
"fmt"
22+
"strings"
23+
24+
"github.com/spf13/cobra"
25+
apierrs "k8s.io/apimachinery/pkg/api/errors"
26+
"sigs.k8s.io/controller-runtime/pkg/client"
27+
28+
cartov1alpha1 "github.com/vmware-tanzu/apps-cli-plugin/pkg/apis/cartographer/v1alpha1"
29+
cli "github.com/vmware-tanzu/apps-cli-plugin/pkg/cli-runtime"
30+
"github.com/vmware-tanzu/apps-cli-plugin/pkg/cli-runtime/validation"
31+
"github.com/vmware-tanzu/apps-cli-plugin/pkg/completion"
32+
"github.com/vmware-tanzu/apps-cli-plugin/pkg/printer"
33+
)
34+
35+
type ClusterSupplyChainGetOptions struct {
36+
Name string
37+
}
38+
39+
var (
40+
_ validation.Validatable = (*ClusterSupplyChainGetOptions)(nil)
41+
_ cli.Executable = (*ClusterSupplyChainGetOptions)(nil)
42+
)
43+
44+
func (opts *ClusterSupplyChainGetOptions) Validate(ctx context.Context) validation.FieldErrors {
45+
errs := validation.FieldErrors{}
46+
if opts.Name == "" {
47+
errs = errs.Also(validation.ErrMissingField(cli.NameArgumentName))
48+
}
49+
return errs
50+
}
51+
52+
func (opts *ClusterSupplyChainGetOptions) Exec(ctx context.Context, c *cli.Config) error {
53+
supplyChain := &cartov1alpha1.ClusterSupplyChain{}
54+
err := c.Get(ctx, client.ObjectKey{Name: opts.Name}, supplyChain)
55+
if err != nil {
56+
if apierrs.IsNotFound(err) {
57+
c.Errorf("Cluster Supply chain %q not found\n", opts.Name)
58+
return cli.SilenceError(err)
59+
}
60+
return err
61+
}
62+
c.Printf(printer.ResourceStatus(supplyChain.Name, printer.FindCondition(supplyChain.Status.Conditions, cartov1alpha1.SupplyChainReady)))
63+
64+
c.Boldf("Supply Chain Selectors\n")
65+
if len(supplyChain.Spec.Selector) == 0 && len(supplyChain.Spec.SelectorMatchExpressions) == 0 && len(supplyChain.Spec.SelectorMatchFields) == 0 {
66+
c.Infof("No supply chain selectors found\n")
67+
} else {
68+
if err := printer.ClusterSupplyChainPrinter(c.Stdout, supplyChain); err != nil {
69+
return err
70+
}
71+
}
72+
return nil
73+
}
74+
func NewClusterSupplyChainGetCommand(ctx context.Context, c *cli.Config) *cobra.Command {
75+
opts := &ClusterSupplyChainGetOptions{}
76+
77+
cmd := &cobra.Command{
78+
Use: "get",
79+
Short: "Get details from a cluster supply chain",
80+
Long: strings.TrimSpace(`Get details from a cluster supply chain`),
81+
Example: strings.Join([]string{
82+
fmt.Sprintf("%s cluster-supply-chain get", c.Name),
83+
}, "\n"),
84+
PreRunE: cli.ValidateE(ctx, opts),
85+
RunE: cli.ExecE(ctx, c, opts),
86+
ValidArgsFunction: completion.SuggestClusterSupplyChainNames(ctx, c),
87+
}
88+
cli.Args(cmd,
89+
cli.NameArg(&opts.Name),
90+
)
91+
92+
return cmd
93+
}

0 commit comments

Comments
 (0)