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

Return the repo name in a carvel a pkg summary #4716

Merged
merged 9 commits into from
May 19, 2022
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,7 @@ func chartCacheKeyFor(namespace, chartID, chartVersion string) (string, error) {
}

var err error
if chartID, err = pkgutils.GetUnescapedChartID(chartID); err != nil {
if chartID, err = pkgutils.GetUnescapedPackageID(chartID); err != nil {
return "", fmt.Errorf("invalid chart ID in chartCacheKeyFor: [%s]: %v", chartID, err)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func (s *Server) getChartInCluster(ctx context.Context, key types.NamespacedName
func (s *Server) availableChartDetail(ctx context.Context, packageRef *corev1.AvailablePackageReference, chartVersion string) (*corev1.AvailablePackageDetail, error) {
log.Infof("+availableChartDetail(%s, %s)", packageRef, chartVersion)

repoN, chartName, err := pkgutils.SplitChartIdentifier(packageRef.Identifier)
repoN, chartName, err := pkgutils.SplitPackageIdentifier(packageRef.Identifier)
if err != nil {
return nil, err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ func (s *Server) getReleaseViaHelmApi(ctx context.Context, key types.NamespacedN
}

func (s *Server) newRelease(ctx context.Context, packageRef *corev1.AvailablePackageReference, targetName types.NamespacedName, versionRef *corev1.VersionReference, reconcile *corev1.ReconciliationOptions, valuesString string) (*corev1.InstalledPackageReference, error) {
repoName, chartName, err := pkgutils.SplitChartIdentifier(packageRef.Identifier)
repoName, chartName, err := pkgutils.SplitPackageIdentifier(packageRef.Identifier)
if err != nil {
return nil, err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ func (s *Server) GetAvailablePackageVersions(ctx context.Context, request *corev
cluster)
}

repoName, chartName, err := pkgutils.SplitChartIdentifier(packageRef.Identifier)
repoName, chartName, err := pkgutils.SplitPackageIdentifier(packageRef.Identifier)
if err != nil {
return nil, err
}
Expand Down
8 changes: 4 additions & 4 deletions cmd/kubeapps-apis/plugins/helm/packages/v1alpha1/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ func (s *Server) GetAvailablePackageDetail(ctx context.Context, request *corev1.
return nil, err
}

unescapedChartID, err := pkgutils.GetUnescapedChartID(request.AvailablePackageRef.Identifier)
unescapedChartID, err := pkgutils.GetUnescapedPackageID(request.AvailablePackageRef.Identifier)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -371,7 +371,7 @@ func (s *Server) GetAvailablePackageVersions(ctx context.Context, request *corev
return nil, err
}

unescapedChartID, err := pkgutils.GetUnescapedChartID(request.GetAvailablePackageRef().GetIdentifier())
unescapedChartID, err := pkgutils.GetUnescapedPackageID(request.GetAvailablePackageRef().GetIdentifier())
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -697,7 +697,7 @@ func (s *Server) CreateInstalledPackage(ctx context.Context, request *corev1.Cre
}
chartID := request.GetAvailablePackageRef().GetIdentifier()
repoNamespace := request.GetAvailablePackageRef().GetContext().GetNamespace()
repoName, chartName, err := pkgutils.SplitChartIdentifier(chartID)
repoName, chartName, err := pkgutils.SplitPackageIdentifier(chartID)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -769,7 +769,7 @@ func (s *Server) UpdateInstalledPackage(ctx context.Context, request *corev1.Upd
return nil, status.Errorf(codes.Internal, "Unable to create kubernetes clientset: %v", err)
}
chartID := availablePkgRef.GetIdentifier()
repoName, chartName, err := pkgutils.SplitChartIdentifier(chartID)
repoName, chartName, err := pkgutils.SplitPackageIdentifier(chartID)
if err != nil {
return nil, err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func (s *Server) GetAvailablePackageSummaries(ctx context.Context, request *core
if currentPkg.Spec.RefName > pkgMetadata.Name {
return nil, status.Errorf(codes.Internal, fmt.Sprintf("unexpected order for kapp-controller packages, expected %q, found %q", pkgMetadata.Name, currentPkg.Spec.RefName))
}
log.Errorf("Package %q did not have a corresponding metadata", currentPkg.Spec.RefName)
log.Errorf("Package %q did not have a corresponding metadata (want %q)", currentPkg.Spec.RefName, pkgMetadata.Name)
currentPkg = <-getPkgsChannel
}
// Collect the packages for a particular refName to be able to send the
Expand Down Expand Up @@ -165,8 +165,13 @@ func (s *Server) GetAvailablePackageVersions(ctx context.Context, request *corev
cluster = s.globalPackagingCluster
}

_, pkgName, err := pkgutils.SplitPackageIdentifier(identifier)
if err != nil {
return nil, err
}

// Use the field selector to return only Package CRs that match on the spec.refName.
fieldSelector := fmt.Sprintf("spec.refName=%s", identifier)
fieldSelector := fmt.Sprintf("spec.refName=%s", pkgName)
pkgs, err := s.getPkgsWithFieldSelector(ctx, cluster, namespace, fieldSelector)
if err != nil {
return nil, statuserror.FromK8sError("get", "Package", "", err)
Expand All @@ -179,8 +184,8 @@ func (s *Server) GetAvailablePackageVersions(ctx context.Context, request *corev

// TODO(minelson): support configurable version summary for kapp-controller pkgs
// as already done for Helm (see #3588 for more info).
versions := make([]*corev1.PackageAppVersion, len(pkgVersionsMap[identifier]))
for i, v := range pkgVersionsMap[identifier] {
versions := make([]*corev1.PackageAppVersion, len(pkgVersionsMap[pkgName]))
for i, v := range pkgVersionsMap[pkgName] {
// Currently, PkgVersion and AppVersion are the same
// https://kubernetes.slack.com/archives/CH8KCCKA5/p1636386358322000?thread_ts=1636371493.320900&cid=CH8KCCKA5
versions[i] = &corev1.PackageAppVersion{
Expand Down Expand Up @@ -215,17 +220,22 @@ func (s *Server) GetAvailablePackageDetail(ctx context.Context, request *corev1.
cluster = s.globalPackagingCluster
}

_, pkgName, err := pkgutils.SplitPackageIdentifier(identifier)
if err != nil {
return nil, err
}

// fetch the package metadata
pkgMetadata, err := s.getPkgMetadata(ctx, cluster, namespace, identifier)
pkgMetadata, err := s.getPkgMetadata(ctx, cluster, namespace, pkgName)
if err != nil {
return nil, statuserror.FromK8sError("get", "PackageMetadata", identifier, err)
return nil, statuserror.FromK8sError("get", "PackageMetadata", pkgName, err)
}

// Use the field selector to return only Package CRs that match on the spec.refName.
fieldSelector := fmt.Sprintf("spec.refName=%s", identifier)
fieldSelector := fmt.Sprintf("spec.refName=%s", pkgName)
pkgs, err := s.getPkgsWithFieldSelector(ctx, cluster, namespace, fieldSelector)
if err != nil {
return nil, statuserror.FromK8sError("get", "Package", identifier, err)
return nil, statuserror.FromK8sError("get", "Package", pkgName, err)
}
pkgVersionsMap, err := getPkgVersionsMap(pkgs)
if err != nil {
Expand All @@ -235,22 +245,22 @@ func (s *Server) GetAvailablePackageDetail(ctx context.Context, request *corev1.
var foundPkgSemver = &pkgSemver{}
if requestedPkgVersion != "" {
// Ensure the version is available.
for _, v := range pkgVersionsMap[identifier] {
for _, v := range pkgVersionsMap[pkgName] {
if v.version.String() == requestedPkgVersion {
foundPkgSemver = &v
break
}
}
if foundPkgSemver.version == nil {
return nil, status.Errorf(codes.NotFound, fmt.Sprintf("unable to find %q package with version %q", identifier, requestedPkgVersion))
return nil, status.Errorf(codes.NotFound, fmt.Sprintf("unable to find %q package with version %q", pkgName, requestedPkgVersion))
}
} else {
// If the pkgVersion wasn't specified, grab the packages to find the latest.
if len(pkgVersionsMap[identifier]) > 0 {
foundPkgSemver = &pkgVersionsMap[identifier][0]
if len(pkgVersionsMap[pkgName]) > 0 {
foundPkgSemver = &pkgVersionsMap[pkgName][0]
requestedPkgVersion = foundPkgSemver.version.String()
} else {
return nil, status.Errorf(codes.NotFound, fmt.Sprintf("unable to find any versions for the package %q", identifier))
return nil, status.Errorf(codes.NotFound, fmt.Sprintf("unable to find any versions for the package %q", pkgName))
}
}

Expand Down Expand Up @@ -551,13 +561,18 @@ func (s *Server) CreateInstalledPackage(ctx context.Context, request *corev1.Cre
}

// Retrieve additional parameters from the request
packageRef := request.GetAvailablePackageRef()
identifier := request.GetAvailablePackageRef().GetIdentifier()
packageCluster := request.GetAvailablePackageRef().GetContext().GetCluster()
packageNamespace := request.GetAvailablePackageRef().GetContext().GetNamespace()
reconciliationOptions := request.GetReconciliationOptions()
pkgVersion := request.GetPkgVersionReference().GetVersion()
values := request.GetValues()

_, pkgName, err := pkgutils.SplitPackageIdentifier(identifier)
if err != nil {
return nil, err
}

if targetCluster == "" {
targetCluster = s.globalPackagingCluster
}
Expand All @@ -572,9 +587,9 @@ func (s *Server) CreateInstalledPackage(ctx context.Context, request *corev1.Cre
}

// fetch the package metadata
pkgMetadata, err := s.getPkgMetadata(ctx, packageCluster, packageNamespace, packageRef.Identifier)
pkgMetadata, err := s.getPkgMetadata(ctx, packageCluster, packageNamespace, pkgName)
if err != nil {
return nil, statuserror.FromK8sError("get", "PackageMetadata", packageRef.Identifier, err)
return nil, statuserror.FromK8sError("get", "PackageMetadata", pkgName, err)
}

// build a new secret object with the values
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,17 @@ func (s *Server) buildAvailablePackageSummary(pkgMetadata *datapackagingv1alpha1
iconStringBuilder.WriteString(pkgMetadata.Spec.IconSVGBase64)
}

// build package identifier based on the metadata
identifier := buildPackageIdentifier(pkgMetadata)

availablePackageSummary := &corev1.AvailablePackageSummary{
AvailablePackageRef: &corev1.AvailablePackageReference{
Context: &corev1.Context{
Cluster: cluster,
Namespace: pkgMetadata.Namespace,
},
Plugin: &pluginDetail,
Identifier: pkgMetadata.Name,
Identifier: identifier,
},
Name: pkgMetadata.Name,
// Currently, PkgVersion and AppVersion are the same
Expand Down Expand Up @@ -85,6 +88,9 @@ func (s *Server) buildAvailablePackageDetail(pkgMetadata *datapackagingv1alpha1.
})
}

// build package identifier based on the metadata
identifier := buildPackageIdentifier(pkgMetadata)

// build readme
readme := buildReadme(pkgMetadata, foundPkgSemver)

Expand All @@ -102,7 +108,7 @@ func (s *Server) buildAvailablePackageDetail(pkgMetadata *datapackagingv1alpha1.
Namespace: pkgMetadata.Namespace,
},
Plugin: &pluginDetail,
Identifier: pkgMetadata.Name,
Identifier: identifier,
},
Name: pkgMetadata.Name,
IconUrl: iconStringBuilder.String(),
Expand Down Expand Up @@ -226,6 +232,9 @@ func (s *Server) buildInstalledPackageDetail(pkgInstall *packagingv1alpha1.Packa
return nil, fmt.Errorf("Cannot get the latest matching version for the pkg %q: %s", pkgMetadata.Name, err.Error())
}

// build package availablePackageIdentifier based on the metadata
availablePackageIdentifier := buildPackageIdentifier(pkgMetadata)

installedPackageDetail := &corev1.InstalledPackageDetail{
InstalledPackageRef: &corev1.InstalledPackageReference{
Context: &corev1.Context{
Expand Down Expand Up @@ -256,8 +265,8 @@ func (s *Server) buildInstalledPackageDetail(pkgInstall *packagingv1alpha1.Packa
Namespace: pkgMetadata.Namespace,
Cluster: cluster,
},
Identifier: pkgInstall.Spec.PackageRef.RefName,
Plugin: &pluginDetail,
Identifier: availablePackageIdentifier,
},
// Currently, PkgVersion and AppVersion are the same
// https://kubernetes.slack.com/archives/CH8KCCKA5/p1636386358322000?thread_ts=1636371493.320900&cid=CH8KCCKA5
Expand Down
Loading