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

parameterize VersionsInSummary - complete fix #3703

Merged
merged 7 commits into from
Nov 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion chart/kubeapps/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ maintainers:
name: kubeapps
sources:
- https://github.com/kubeapps/kubeapps
version: 7.5.12-dev1
version: 7.5.12-dev2
9 changes: 9 additions & 0 deletions chart/kubeapps/templates/kubeappsapis/configmap.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ template "kubeapps.kubeappsapis.fullname" . }}-configmap
data:
plugins.conf: |-
{{- if .Values.kubeappsapis.pluginConfig }}
{{ .Values.kubeappsapis.pluginConfig | toPrettyJson | indent 4 }}
{{- end }}
satya-dillikar marked this conversation as resolved.
Show resolved Hide resolved
16 changes: 14 additions & 2 deletions chart/kubeapps/templates/kubeappsapis/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ spec:
{{- if .Values.clusters }}
- --clusters-config-path=/config/clusters.conf
{{- end }}
{{- if .Values.kubeappsapis.pluginConfig }}
- --plugin-config-path=/config/kubeapps-apis/plugins.conf
{{- end }}
{{- if .Values.pinnipedProxy.enabled }}
- --pinniped-proxy-url=http://{{ template "kubeapps.pinniped-proxy.fullname" . }}.{{ .Release.Namespace }}:{{ .Values.pinnipedProxy.containerPort }}
{{- end }}
Expand Down Expand Up @@ -145,18 +148,27 @@ spec:
{{- if .Values.kubeappsapis.resources }}
resources: {{- toYaml .Values.kubeappsapis.resources | nindent 12 }}
{{- end }}
{{- if .Values.clusters }}
volumeMounts:
{{- if .Values.clusters }}
- name: clusters-config
mountPath: /config
- name: ca-certs
mountPath: /etc/additional-clusters-cafiles
{{- end }}
{{- if .Values.clusters }}
{{- if .Values.kubeappsapis.pluginConfig }}
- name: plugins-config
mountPath: /config/kubeapps-apis
satya-dillikar marked this conversation as resolved.
Show resolved Hide resolved
{{- end }}
volumes:
{{- if .Values.clusters }}
- name: clusters-config
configMap:
name: {{ template "kubeapps.clusters-config.fullname" . }}
- name: ca-certs
emptyDir: {}
{{- end }}
{{- if .Values.kubeappsapis.pluginConfig }}
- name: plugins-config
configMap:
name: {{ template "kubeapps.kubeappsapis.fullname" . }}-configmap
{{- end }}
11 changes: 11 additions & 0 deletions chart/kubeapps/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1599,6 +1599,17 @@ kubeappsapis:
##
enabledPlugins:
- helm
## @param kubeappsapis.pluginConfig Additional configurations for each plugin
## e.g:
## versionsInSummary{major, minor, patch}
pluginConfig:
core:
packages:
v1alpha1:
versionsInSummary:
major: 3
minor: 3
patch: 3
## Bitnami Kubeapps-APIs image
## ref: https://hub.docker.com/r/bitnami/kubeapps-apis/tags/
## @param kubeappsapis.image.registry Kubeapps-APIs image registry
Expand Down
1 change: 1 addition & 0 deletions cmd/kubeapps-apis/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ func setFlags(c *cobra.Command) {
c.Flags().IntVar(&serveOpts.Port, "port", 50051, "The port on which to run this api server. Both gRPC and HTTP requests will be served on this port.")
c.Flags().StringSliceVar(&serveOpts.PluginDirs, "plugin-dir", []string{"."}, "A directory to be scanned for .so plugins. May be specified multiple times.")
c.Flags().StringVar(&serveOpts.ClustersConfigPath, "clusters-config-path", "", "Configuration for clusters")
c.Flags().StringVar(&serveOpts.PluginConfigPath, "plugin-config-path", "", "Configuration for plugins")
c.Flags().StringVar(&serveOpts.PinnipedProxyURL, "pinniped-proxy-url", "http://kubeapps-internal-pinniped-proxy.kubeapps:3333", "internal url to be used for requests to clusters configured for credential proxying via pinniped")
c.Flags().BoolVar(&serveOpts.UnsafeLocalDevKubeconfig, "unsafe-local-dev-kubeconfig", false, "if true, it will use the local kubeconfig at the KUBECONFIG env var instead of using the inCluster configuration.")
}
Expand Down
3 changes: 2 additions & 1 deletion cmd/kubeapps-apis/plugins/fluxv2/packages/v1alpha1/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ func init() {

// RegisterWithGRPCServer enables a plugin to register with a gRPC server
// returning the server implementation.
func RegisterWithGRPCServer(s grpc.ServiceRegistrar, configGetter server.KubernetesConfigGetter, clustersConfig kube.ClustersConfig) (interface{}, error) {
func RegisterWithGRPCServer(s grpc.ServiceRegistrar, configGetter server.KubernetesConfigGetter,
clustersConfig kube.ClustersConfig, pluginConfigPath string) (interface{}, error) {
log.Infof("+fluxv2 RegisterWithGRPCServer")
svr, err := NewServer(configGetter, clustersConfig.KubeappsClusterName)
if err != nil {
Expand Down
5 changes: 3 additions & 2 deletions cmd/kubeapps-apis/plugins/helm/packages/v1alpha1/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,9 @@ func init() {

// RegisterWithGRPCServer enables a plugin to register with a gRPC server
// returning the server implementation.
func RegisterWithGRPCServer(s grpc.ServiceRegistrar, configGetter server.KubernetesConfigGetter, clustersConfig kube.ClustersConfig) (interface{}, error) {
svr := NewServer(configGetter, clustersConfig.KubeappsClusterName)
func RegisterWithGRPCServer(s grpc.ServiceRegistrar, configGetter server.KubernetesConfigGetter,
clustersConfig kube.ClustersConfig, pluginConfigPath string) (interface{}, error) {
svr := NewServer(configGetter, clustersConfig.KubeappsClusterName, pluginConfigPath)
v1alpha1.RegisterHelmPackagesServiceServer(s, svr)
return svr, nil
}
Expand Down
63 changes: 57 additions & 6 deletions cmd/kubeapps-apis/plugins/helm/packages/v1alpha1/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"net/url"
"os"
"strconv"
Expand Down Expand Up @@ -65,6 +66,13 @@ const (
UserAgentPrefix = "kubeapps-apis/plugins"
)

// Wapper struct to include three version constants
type VersionsInSummary struct {
Major int `json:"major"`
Minor int `json:"minor"`
Patch int `json:"patch"`
}

// Server implements the helm packages v1alpha1 interface.
type Server struct {
v1alpha1.UnimplementedHelmPackagesServiceServer
Expand All @@ -77,11 +85,49 @@ type Server struct {
manager utils.AssetManager
actionConfigGetter helmActionConfigGetter
chartClientFactory chartutils.ChartClientFactoryInterface
versionsInSummary VersionsInSummary
}

// parsePluginConfig parses the input plugin configuration json file and return the configuration options.
func parsePluginConfig(pluginConfigPath string) VersionsInSummary {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For now this is fine, since VersionsInSummary is the only configurable option for the plugin, but I assume in the future we'd be returning the helmConfig struct.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I shall keep as-is for now. But updated comments in the code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please review the new set of changes in my new commit on Nov3
"add new TC & configmap"

I had some merge issues, hence you will see more commits. Please ignore those.
Thanks again.


// Note at present VersionsInSummary is the only configurable option for this plugin,
// and if required this func can be enhaned to return helmConfig struct

// In the helm plugin, for example, we are interested in config for the
// core.packages.v1alpha1 only. So the plugin defines the following struct and parses the config.
type helmConfig struct {
Core struct {
Packages struct {
V1alpha1 struct {
VersionsInSummary VersionsInSummary
} `json:"v1alpha1"`
} `json:"packages"`
} `json:"core"`
}
var config helmConfig

pluginConfig, err := ioutil.ReadFile(pluginConfigPath)
if err != nil {
// return default value of VersionsInSummary
return VersionsInSummary{MajorVersionsInSummary,
MinorVersionsInSummary, PatchVersionsInSummary}
}
err = json.Unmarshal([]byte(pluginConfig), &config)
if err != nil {
// return default value of VersionsInSummary
return VersionsInSummary{MajorVersionsInSummary,
MinorVersionsInSummary, PatchVersionsInSummary}
}

// return configured value of VersionsInSummary
return config.Core.Packages.V1alpha1.VersionsInSummary

}

// NewServer returns a Server automatically configured with a function to obtain
// the k8s client config.
func NewServer(configGetter server.KubernetesConfigGetter, globalPackagingCluster string) *Server {
func NewServer(configGetter server.KubernetesConfigGetter, globalPackagingCluster string, pluginConfigPath string) *Server {
var kubeappsNamespace = os.Getenv("POD_NAMESPACE")
var ASSET_SYNCER_DB_URL = os.Getenv("ASSET_SYNCER_DB_URL")
var ASSET_SYNCER_DB_NAME = os.Getenv("ASSET_SYNCER_DB_NAME")
Expand All @@ -99,6 +145,9 @@ func NewServer(configGetter server.KubernetesConfigGetter, globalPackagingCluste
log.Fatalf("%s", err)
}

versionsInSummary := parsePluginConfig(pluginConfigPath)
log.Infof("NewServer: versionsInSummary %v\n", versionsInSummary)
satya-dillikar marked this conversation as resolved.
Show resolved Hide resolved

return &Server{
clientGetter: func(ctx context.Context, cluster string) (kubernetes.Interface, dynamic.Interface, error) {
if configGetter == nil {
Expand Down Expand Up @@ -151,6 +200,7 @@ func NewServer(configGetter server.KubernetesConfigGetter, globalPackagingCluste
globalPackagingNamespace: kubeappsNamespace,
globalPackagingCluster: globalPackagingCluster,
chartClientFactory: &chartutils.ChartClientFactory{},
versionsInSummary: versionsInSummary,
}
}

Expand Down Expand Up @@ -430,13 +480,14 @@ func (s *Server) GetAvailablePackageVersions(ctx context.Context, request *corev
if err != nil {
return nil, status.Errorf(codes.Internal, "Unable to retrieve chart: %v", err)
}

return &corev1.GetAvailablePackageVersionsResponse{
PackageAppVersions: packageAppVersionsSummary(chart.ChartVersions),
PackageAppVersions: packageAppVersionsSummary(chart.ChartVersions, s.versionsInSummary),
}, nil
}

// packageAppVersionsSummary converts the model chart versions into the required version summary.
func packageAppVersionsSummary(versions []models.ChartVersion) []*corev1.PackageAppVersion {
func packageAppVersionsSummary(versions []models.ChartVersion, versionInSummary VersionsInSummary) []*corev1.PackageAppVersion {
pav := []*corev1.PackageAppVersion{}

// Use a version map to be able to count how many major, minor and patch versions
Expand All @@ -450,18 +501,18 @@ func packageAppVersionsSummary(versions []models.ChartVersion) []*corev1.Package

if _, ok := version_map[version.Major()]; !ok {
// Don't add a new major version if we already have enough
if len(version_map) >= MajorVersionsInSummary {
if len(version_map) >= versionInSummary.Major {
continue
}
} else {
// If we don't yet have this minor version
if _, ok := version_map[version.Major()][version.Minor()]; !ok {
// Don't add a new minor version if we already have enough for this major version
if len(version_map[version.Major()]) >= MinorVersionsInSummary {
if len(version_map[version.Major()]) >= versionInSummary.Minor {
continue
}
} else {
if len(version_map[version.Major()][version.Minor()]) >= PatchVersionsInSummary {
if len(version_map[version.Major()][version.Minor()]) >= versionInSummary.Patch {
continue
}
}
Expand Down
Loading