astefanutti commented on code in PR #3402:
URL: https://github.com/apache/camel-k/pull/3402#discussion_r910722871


##########
e2e/support/test_support.go:
##########
@@ -1933,3 +1933,9 @@ func GetOutputStringAsync(cmd *cobra.Command) func() 
string {
                return buffer.String()
        }
 }
+
+func IsAPIResourceInstalled(t *testing.T, client client.Client, groupVersion 
string, obj interface{}) bool {

Review Comment:
   Can't `kubernetes.IsAPIResourceInstalled` be used?



##########
pkg/trait/mount.go:
##########
@@ -118,13 +119,15 @@ func (t *mountTrait) Apply(e *Environment) error {
                return err
        }
 
-       // CronJob
-       if err := e.Resources.VisitCronJobE(func(cron *v1beta1.CronJob) error {
-               volumes = &cron.Spec.JobTemplate.Spec.Template.Spec.Volumes
-               visited = true
-               return nil
-       }); err != nil {
-               return err
+       if ok, err := kubernetes.IsAPIResourceInstalled(e.Client, 
batchv1.SchemeGroupVersion.String(), reflect.TypeOf(batchv1.CronJob{}).Name()); 
ok && err == nil {

Review Comment:
   Is this really necessary? My understanding is that there is no server API 
requests made while visiting the resources?



##########
pkg/cmd/operator/operator.go:
##########
@@ -193,6 +193,23 @@ func Run(healthPort, monitoringPort int32, leaderElection 
bool, leaderElectionID
        exitOnError(err, "cannot create Integration label selector")
        selector := labels.NewSelector().Add(*hasIntegrationLabel)
 
+       selectors := cache.SelectorsByObject{
+               &corev1.Pod{}:        {Label: selector},
+               &appsv1.Deployment{}: {Label: selector},
+               &batchv1.Job{}:       {Label: selector},
+               &servingv1.Service{}: {Label: selector},
+       }
+
+       if ok, err := kubernetes.IsAPIResourceInstalled(c, 
batchv1.SchemeGroupVersion.String(), reflect.TypeOf(batchv1.CronJob{}).Name()); 
ok && err == nil {
+               selectors = cache.SelectorsByObject{
+                       &corev1.Pod{}:        {Label: selector},
+                       &appsv1.Deployment{}: {Label: selector},
+                       &batchv1.CronJob{}:   {Label: selector},
+                       &batchv1.Job{}:       {Label: selector},
+                       &servingv1.Service{}: {Label: selector},
+               }

Review Comment:
   Maybe:
   ```go
   selectors[&batchv1beta1.CronJob{}] = struct {
        Label labels.Selector
        Field fields.Selector
   }{
        Label: selector,
   }
   ```
   instead of duplicating the whole initialisation.



##########
pkg/trait/container.go:
##########
@@ -297,17 +298,19 @@ func (t *containerTrait) configureContainer(e 
*Environment) error {
                return err
        }
 
-       // CronJob
-       if err := e.Resources.VisitCronJobE(func(cron *v1beta1.CronJob) error {
-               for _, envVar := range e.EnvVars {
-                       envvar.SetVar(&container.Env, envVar)
-               }
+       if ok, err := kubernetes.IsAPIResourceInstalled(e.Client, 
batchv1.SchemeGroupVersion.String(), reflect.TypeOf(batchv1.CronJob{}).Name()); 
ok && err == nil {

Review Comment:
   Is this really necessary? My understanding is that there is no server API 
requests made while visiting the resources?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to