diff --git a/VERSION b/VERSION index 0dd8454758dfe..5d0378e277470 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -2.8.1-cap-CR-20837 \ No newline at end of file +2.8.1-cap-CR-20837 diff --git a/pkg/apiclient/events/events.pb.go b/pkg/apiclient/events/events.pb.go index 939664e1f51d6..5f19438b95c2f 100644 --- a/pkg/apiclient/events/events.pb.go +++ b/pkg/apiclient/events/events.pb.go @@ -540,7 +540,7 @@ func (m *ObjectError) GetLastSeen() v1.Time { type Dependencies struct { // Content of Chart.lock Lock *string `protobuf:"bytes,1,opt,name=lock" json:"lock,omitempty"` - // Content of Cart.yaml/dependencies + // Content of Chart.yaml Deps *string `protobuf:"bytes,2,opt,name=deps" json:"deps,omitempty"` // Content of requirements.yaml Requirements *string `protobuf:"bytes,3,opt,name=requirements" json:"requirements,omitempty"` diff --git a/pkg/version_config_manager/version_config_manager.go b/pkg/version_config_manager/version_config_manager.go index c4be2e79ca946..46ba14d83a0fe 100644 --- a/pkg/version_config_manager/version_config_manager.go +++ b/pkg/version_config_manager/version_config_manager.go @@ -2,6 +2,7 @@ package version_config_manager import ( "errors" + log "github.com/sirupsen/logrus" ) @@ -78,7 +79,7 @@ func GetVersionConfig() *VersionConfig { versionConfig, err := versionConfigManager.ObtainConfig() if err != nil { - log.Printf("ERROR: Failed to obtain config: %v", err) + log.Printf("Failed to obtain config: %v", err) return nil } diff --git a/reposerver/repository/app_version.go b/reposerver/repository/app_version.go index 40e4843729df6..1f9213a62d2fa 100644 --- a/reposerver/repository/app_version.go +++ b/reposerver/repository/app_version.go @@ -3,6 +3,7 @@ package repository import ( "os" "path/filepath" + "reflect" "strings" log "github.com/sirupsen/logrus" @@ -21,35 +22,14 @@ type Result struct { Dependencies DependenciesMap `json:"dependencies"` } -func getDependenciesFromChart(appPath string) (*string, error) { - content, err := os.ReadFile(appPath) - if err != nil { - return nil, err - } - - var obj map[interface{}]interface{} - if err := yaml.Unmarshal(content, &obj); err != nil { - return nil, err - } - - var dependenciesStr string - if obj["dependencies"] != nil { - dependencies, err := yaml.Marshal(&map[interface{}]interface{}{"dependencies": obj["dependencies"]}) - if err != nil { - return nil, err - } - dependenciesStr = string(dependencies) - } - - return &dependenciesStr, nil -} - func getVersionFromYaml(appPath, jsonPathExpression string) (*string, error) { content, err := os.ReadFile(appPath) if err != nil { return nil, err } + log.Infof("AppVersion source content: %s", string(content)) + var obj interface{} if err := yaml.Unmarshal(content, &obj); err != nil { return nil, err @@ -74,6 +54,7 @@ func getVersionFromYaml(appPath, jsonPathExpression string) (*string, error) { } appVersion := buf.String() + log.Infof("AppVersion source content appVersion: %s", appVersion) return &appVersion, nil } @@ -89,6 +70,17 @@ func convertToJSONCompatible(i interface{}) (interface{}, error) { return obj, nil } +func readFileContent(result *Result, appPath, fileName, fieldName string) { + content, err := os.ReadFile(filepath.Join(appPath, fileName)) + if err == nil && content != nil { + v := reflect.ValueOf(result).Elem() + f := v.FieldByName("Dependencies").FieldByName(fieldName) + if f.IsValid() && f.CanSet() && f.Kind() == reflect.String { + f.SetString(string(content)) + } + } +} + func getAppVersions(appPath string, resourceName string, jsonPathExpression string) (*Result, error) { // Defaults if resourceName == "" { @@ -103,30 +95,16 @@ func getAppVersions(appPath string, resourceName string, jsonPathExpression stri if err != nil { return nil, err } - log.Printf("appVersion value: %v\n", *appVersion) + log.Infof("appVersion value: %v (appPath=%s)", *appVersion, appPath) result := &Result{ AppVersion: *appVersion, Dependencies: DependenciesMap{}, } - // Get Chart.lock if exists - lock, err := os.ReadFile(filepath.Join(appPath, "Chart.lock")) - if err == nil && lock != nil { - result.Dependencies.Lock = string(lock) - } - - // Get `dependencies` property from Chart.yaml if exists - deps, err := getDependenciesFromChart(filepath.Join(appPath, resourceName)) - if err == nil && deps != nil { - result.Dependencies.Deps = *deps - } - - // Get requirements.yaml if exists - requirements, err := os.ReadFile(filepath.Join(appPath, "requirements.yaml")) - if err == nil && requirements != nil { - result.Dependencies.Requirements = string(requirements) - } + readFileContent(result, appPath, "Chart.lock", "Lock") + readFileContent(result, appPath, "Chart.yaml", "Deps") + readFileContent(result, appPath, "requirements.yaml", "Requirements") return result, nil } diff --git a/server/application/application_event_reporter.go b/server/application/application_event_reporter.go index 9019238bbf07e..917dfee6ca4bd 100644 --- a/server/application/application_event_reporter.go +++ b/server/application/application_event_reporter.go @@ -161,7 +161,7 @@ func (s *applicationEventReporter) streamApplicationEvents( logCtx.WithError(err).Warn("failed to get parent application's revision metadata, resuming") } - err = s.processResource(ctx, *rs, parentApplicationEntity, logCtx, ts, parentDesiredManifests, stream, appTree, es, manifestGenErr, a, parentRevisionMetadata, true, appInstanceLabelKey, trackingMethod) + err = s.processResource(ctx, *rs, parentApplicationEntity, logCtx, ts, parentDesiredManifests, stream, appTree, es, manifestGenErr, a, parentRevisionMetadata, true, appInstanceLabelKey, trackingMethod, desiredManifests.ApplicationVersions) if err != nil { return err } @@ -191,7 +191,7 @@ func (s *applicationEventReporter) streamApplicationEvents( continue } - err := s.processResource(ctx, rs, a, logCtx, ts, desiredManifests, stream, appTree, es, manifestGenErr, nil, revisionMetadata, ignoreResourceCache, appInstanceLabelKey, trackingMethod) + err := s.processResource(ctx, rs, a, logCtx, ts, desiredManifests, stream, appTree, es, manifestGenErr, nil, revisionMetadata, ignoreResourceCache, appInstanceLabelKey, trackingMethod, nil) if err != nil { return err } @@ -240,6 +240,7 @@ func (s *applicationEventReporter) processResource( ignoreResourceCache bool, appInstanceLabelKey string, trackingMethod appv1.TrackingMethod, + applicationVersions *apiclient.ApplicationVersions, ) error { logCtx = logCtx.WithFields(log.Fields{ "gvk": fmt.Sprintf("%s/%s/%s", rs.Group, rs.Version, rs.Kind), @@ -297,7 +298,7 @@ func (s *applicationEventReporter) processResource( originalAppRevisionMetadata, _ = s.getApplicationRevisionDetails(ctx, originalApplication, getOperationRevision(originalApplication)) } - ev, err := getResourceEventPayload(parentApplicationToReport, &rs, es, actualState, desiredState, appTree, manifestGenErr, ts, originalApplication, revisionMetadataToReport, originalAppRevisionMetadata, appInstanceLabelKey, trackingMethod, desiredManifests.ApplicationVersions) + ev, err := getResourceEventPayload(parentApplicationToReport, &rs, es, actualState, desiredState, appTree, manifestGenErr, ts, originalApplication, revisionMetadataToReport, originalAppRevisionMetadata, appInstanceLabelKey, trackingMethod, applicationVersions) if err != nil { logCtx.WithError(err).Warn("failed to get event payload, resuming") return nil @@ -471,8 +472,6 @@ func getResourceEventPayload( if originalApplication != nil { logCtx = log.WithField("application", originalApplication.Name) - } else if parentApplication != nil { - logCtx = log.WithField("application", parentApplication.Name) } else { logCtx = log.NewEntry(log.StandardLogger()) } @@ -613,6 +612,8 @@ func getResourceEventPayload( AppVersions: applicationVersionsEvents, } + logCtx.Infof("AppVersion before encoding: %v", safeString(payload.AppVersions.AppVersion)) + payloadBytes, err := json.Marshal(&payload) if err != nil { return nil, fmt.Errorf("failed to marshal payload for resource %s/%s: %w", rs.Namespace, rs.Name, err) @@ -720,6 +721,8 @@ func (s *applicationEventReporter) getApplicationEventPayload( AppVersions: applicationVersionsEvents, } + logCtx.Infof("AppVersion before encoding: %v", safeString(payload.AppVersions.AppVersion)) + payloadBytes, err := json.Marshal(&payload) if err != nil { return nil, fmt.Errorf("failed to marshal payload for resource %s/%s: %w", a.Namespace, a.Name, err) @@ -799,3 +802,10 @@ func repoAppVersionsToEvent(applicationVersions *apiclient.ApplicationVersions) } return applicationVersionsEvents, nil } + +func safeString(s *string) string { + if s == nil { + return "" + } + return *s +} diff --git a/server/application/application_event_reporter_test.go b/server/application/application_event_reporter_test.go index 6ca65058062a9..a60679cb22a40 100644 --- a/server/application/application_event_reporter_test.go +++ b/server/application/application_event_reporter_test.go @@ -60,7 +60,7 @@ func TestGetResourceEventPayload(t *testing.T) { Message: "some message", } - event, err := getResourceEventPayload(&app, &rs, &es, &actualState, &desiredState, &appTree, true, "", nil, &revisionMetadata, nil, common.LabelKeyAppInstance, argo.TrackingMethodLabel, nil) + event, err := getResourceEventPayload(&app, &rs, &es, &actualState, &desiredState, &appTree, true, "", nil, &revisionMetadata, nil, common.LabelKeyAppInstance, argo.TrackingMethodLabel, &apiclient.ApplicationVersions{}) assert.NoError(t, err) var eventPayload events.EventPayload @@ -96,7 +96,7 @@ func TestGetResourceEventPayload(t *testing.T) { Message: "some message", } - event, err := getResourceEventPayload(&app, &rs, &es, &actualState, &desiredState, &appTree, true, "", nil, &revisionMetadata, nil, common.LabelKeyAppInstance, argo.TrackingMethodLabel, nil) + event, err := getResourceEventPayload(&app, &rs, &es, &actualState, &desiredState, &appTree, true, "", nil, &revisionMetadata, nil, common.LabelKeyAppInstance, argo.TrackingMethodLabel, &apiclient.ApplicationVersions{}) assert.NoError(t, err) var eventPayload events.EventPayload @@ -375,7 +375,7 @@ func TestGetResourceEventPayloadWithoutRevision(t *testing.T) { } appTree := v1alpha1.ApplicationTree{} - _, err := getResourceEventPayload(&app, &rs, &es, &actualState, &desiredState, &appTree, true, "", nil, nil, nil, common.LabelKeyAppInstance, argo.TrackingMethodLabel, nil) + _, err := getResourceEventPayload(&app, &rs, &es, &actualState, &desiredState, &appTree, true, "", nil, nil, nil, common.LabelKeyAppInstance, argo.TrackingMethodLabel, &apiclient.ApplicationVersions{}) assert.NoError(t, err) } diff --git a/server/application/events.proto b/server/application/events.proto index 18c865b712b5c..bcd8bf16a265d 100644 --- a/server/application/events.proto +++ b/server/application/events.proto @@ -90,12 +90,12 @@ message ObjectError { optional string level = 2 [(gogoproto.nullable) = false]; optional string message = 3 [(gogoproto.nullable) = false]; optional k8s.io.apimachinery.pkg.apis.meta.v1.Time lastSeen = 4 [(gogoproto.nullable) = false]; -} +} message Dependencies { // Content of Chart.lock optional string lock = 1; - // Content of Cart.yaml/dependencies + // Content of Chart.yaml optional string deps = 2; // Content of requirements.yaml optional string requirements = 3;