Skip to content

Commit 5efe142

Browse files
committed
tweak workload image and update pod reconciler go file
1 parent 0530b4a commit 5efe142

File tree

6 files changed

+77
-45
lines changed

6 files changed

+77
-45
lines changed

cleanup.sh

+46-21
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,50 @@ set -euo pipefail
33
# make sure to regenerate manifests and run tests
44
make all
55

6+
# delete existing workload
7+
if [[ -n $( kubectl get podintent.conventions.carto.run/spring-sample -n my-apps) ]]; then
8+
kubectl delete -f samples/ytt-based-conventions/workload.yaml
9+
fi
10+
611
# delete any existing convention and deployment
7-
kubectl delete -f samples/ytt-based-conventions/ytt-example.yaml
8-
kapp delete -a conventions -n cartographer-system
9-
10-
# create a new deployment
11-
kapp deploy -n cartographer-system -a conventions -f <( \
12-
ko resolve -f <( \
13-
ytt \
14-
-f dist/cartographer-conventions.yaml
15-
) \
16-
)
17-
18-
# create the ytt based convention
19-
kubectl apply -f samples/ytt-based-conventions/ytt-example.yaml
20-
#kubectl delete -f samples/ytt-based-conventions/ytt-example.yaml
21-
22-
# inspect the ytt based convention
23-
kubectl get clusterpodconvention.conventions.carto.run/spring-ytt-sample -o yaml
24-
25-
# create a workload
26-
kubectl apply -f samples/ytt-based-conventions/workload.yaml
27-
#kubectl delete -f samples/ytt-based-conventions/workload.yaml
12+
if [[ -n $(kubectl get clusterpodconvention.conventions.carto.run/spring-ytt-sample) ]]; then
13+
kubectl delete -f samples/ytt-based-conventions/ytt-example.yaml
14+
fi
15+
16+
# delete convention deployent if it exists
17+
if [[ -n $( kapp list -n cartographer-system | grep 'conventions') ]]; then
18+
kapp delete -a conventions -n cartographer-system -y
19+
fi
20+
21+
22+
if [[ -n $(kubectl get secret image-pull-secret -n my-apps) ]]; then
23+
# delete existing secret
24+
kubectl delete secret image-pull-secret -n my-apps
25+
else
26+
# create secret with credentials
27+
kubectl create secret docker-registry image-pull-secret \
28+
--docker-server='dev.registry.tanzu.vmware.com' \
29+
--docker-username='robot$tap-integrations+ytt-feature-test' \
30+
--docker-password="qMkLheVd3EwrRzUesdCjBDFZAhkD5Jzf" \
31+
-n my-apps
32+
33+
fi
34+
35+
# make a new deployment
36+
# kapp deploy -n cartographer-system -a conventions -f <( \
37+
# ko resolve -f <( \
38+
# ytt \
39+
# -f dist/cartographer-conventions.yaml
40+
# ) \
41+
# )
42+
43+
# # create the ytt based convention
44+
# kubectl apply -f samples/ytt-based-conventions/ytt-example.yaml
45+
# #kubectl delete -f samples/ytt-based-conventions/ytt-example.yaml
46+
47+
# # inspect the ytt based convention
48+
# kubectl get clusterpodconvention.conventions.carto.run/spring-ytt-sample -o yaml
49+
50+
# # create a workload
51+
# kubectl apply -f samples/ytt-based-conventions/workload.yaml
52+
# #kubectl delete -f samples/ytt-based-conventions/workload.yaml

pkg/apis/conventions/v1alpha1/clusterpodconvention_defaults.go

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ func (s *ClusterPodConventionSpec) Default() {
3636
}
3737

3838
// only set this default if ytt is not the current configuration
39+
// ensure that we only set the default if ytt is not set
3940
if s.Webhook != nil && s.Ytt == nil {
4041
s.Webhook.Default()
4142
}

pkg/apis/conventions/v1alpha1/clusterpodconvention_validation.go

+7-1
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,19 @@ func (s *ClusterPodConventionSpec) Validate() validation.FieldErrors {
7474

7575
// The Webhook and Ytt configurations are nutually exclusive
7676
// return error if neither is provided
77+
//
7778
if s.Webhook == nil && s.Ytt == nil {
7879
errs = errs.Also(validation.ErrMissingField("webhook")).Also(validation.ErrMissingField("ytt"))
7980

8081
} else {
8182
// only invoke webhook specific validations if the ytt configuration is not being used
82-
if s.Ytt == nil && s.Webhook != nil {
83+
if s.Webhook != nil {
84+
// this if check ensures we do not get `webhook configuration must have either service`
8385
errs = errs.Also(s.Webhook.Validate().ViaField("webhook"))
8486
}
87+
// if s.Ytt != nil {
88+
// errs = errs.Also(s.Ytt.ValidateYtt().ViaField("ytt"))
89+
// }
8590
}
8691

8792
if s.SelectorTarget != PodTemplateSpecLabels && s.SelectorTarget != PodIntentLabels {
@@ -95,6 +100,7 @@ func (s *ClusterPodConventionSpec) Validate() validation.FieldErrors {
95100

96101
func (s *ClusterPodConventionYttTemplate) ValidateYtt() validation.FieldErrors {
97102
errs := validation.FieldErrors{}
103+
98104
if s.Template == "" {
99105
errs = errs.Also(validation.ErrMissingField("template"))
100106
}

pkg/controllers/podintent_reconciler.go

+19-22
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,10 @@ func ResolveConventions() reconcilers.SubReconciler {
124124

125125
log.Info("created convention ... ", convention)
126126

127+
// assuming the validation of the convention ensures that we handle these in a
128+
// mutually exclusive fashion
127129
if source.Spec.Webhook != nil {
130+
log.Info("handling a webhook based convetion", source.Spec.Webhook)
128131
clientConfig := source.Spec.Webhook.ClientConfig.DeepCopy()
129132
if source.Spec.Webhook.Certificate != nil {
130133
caBundle, err := getCABundle(ctx, c, source.Spec.Webhook.Certificate, parent)
@@ -138,15 +141,23 @@ func ResolveConventions() reconcilers.SubReconciler {
138141
}
139142
convention.ClientConfig = *clientConfig
140143
} else if source.Spec.Ytt != nil {
141-
log.Info("handling a ytt based convention")
142-
log.Info("retrieved pod template spec from the workload", parent)
144+
log.Info("handling a ytt based convention", "ytt convention", source.Spec.Ytt)
145+
log.Info("retrieved pod template spec from the workload", "templatespec", parent.Spec.Template.AsPodTemplateSpec())
146+
147+
ExecCall(ctx)
148+
149+
// get package bianry dir
150+
// path, err := os.Executable()
151+
// if err != nil {
152+
// log.Info(" current working directory", "path", path)
153+
// }
154+
// fmt.Println(path)
143155

144156
// stampedObj, err := ApplyYtt(ctx, *parent)
145157
// if err != nil {
146158
// return nil
147159
// }
148160
// log.Info("stamped out object", stampedObj)
149-
ExecCall()
150161
}
151162
conventions = append(conventions, convention)
152163
}
@@ -164,23 +175,19 @@ func ResolveConventions() reconcilers.SubReconciler {
164175
}
165176
}
166177

167-
func ExecCall() {
168-
app := "echo"
178+
func ExecCall(ctx context.Context) {
179+
app := "kubectl"
180+
// log := logr.FromContextOrDiscard(ctx)
169181

170-
arg0 := "-e"
171-
arg1 := "Hello world"
172-
arg2 := "\n\tfrom"
173-
arg3 := "golang"
174-
175-
cmd := exec.Command(app, arg0, arg1, arg2, arg3)
182+
args := []string{"--version"}
183+
cmd := exec.CommandContext(ctx, app, args...)
176184
stdout, err := cmd.Output()
177185

178186
if err != nil {
179187
fmt.Println(err.Error())
180188
return
181189
}
182190
fmt.Println(string(stdout))
183-
184191
}
185192

186193
func ApplyYtt(ctx context.Context, workload conventionsv1alpha1.PodIntent) (interface{}, error) {
@@ -198,16 +205,6 @@ func ApplyYtt(ctx context.Context, workload conventionsv1alpha1.PodIntent) (inte
198205
ytt = path.Join(kodata, fmt.Sprintf("ytt-%s-%s", runtime.GOOS, runtime.GOARCH))
199206
}
200207

201-
// toolsBinDir := filepath.Join(projectRootDir, constants.ToolsBinDirPath)
202-
// ytt_command := exec.Command(
203-
// filepath.Join(toolsBinDir, "ytt"),
204-
// "-f-",
205-
// "-f", packageHelpersLibFile,
206-
// "-f", packageValuesFile,
207-
// "-v", "packageRepository="+packageRepository,
208-
// "-v", "registry="+registry,
209-
// ) //
210-
211208
args := []string{"--version"}
212209
stdin := bytes.NewReader([]byte(template.Spec.String()))
213210
stdout := bytes.NewBuffer([]byte{})

samples/ytt-based-conventions/workload.yaml

+4-1
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,12 @@ apiVersion: conventions.carto.run/v1alpha1
33
kind: PodIntent
44
metadata:
55
name: spring-sample
6+
namespace: my-apps
67
spec:
78
template:
89
spec:
910
containers:
1011
- name: workload
11-
image: scothis/petclinic:sbom-20211210@sha256:8b517f21f283229e855e316e2753396239884eb9c4009ab6c797bdf2a041140f
12+
image: dev.registry.tanzu.vmware.com/tap-integrations/spring-pet-clinic@sha256:ba58ba2e2c8cdbad9eaf2aa5b4cba1bb324808326bfa708c34c7208c5a9e7df0
13+
imagePullSecrets:
14+
- name: image-pull-secret

0 commit comments

Comments
 (0)