Skip to content

Commit

Permalink
describe insights and add more details
Browse files Browse the repository at this point in the history
  • Loading branch information
floreks committed Sep 9, 2024
1 parent 875e78a commit b39308f
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 6 deletions.
47 changes: 42 additions & 5 deletions internal/controller/upgradeinsights_cloudprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/samber/lo"
corev1 "k8s.io/api/core/v1"
runtimeclient "sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/log"

"github.com/pluralsh/deployment-operator/api/v1alpha1"
)
Expand All @@ -39,7 +40,7 @@ func (in *EKSCloudProvider) UpgradeInsights(ctx context.Context, ui v1alpha1.Upg
return nil, err
}

return algorithms.Map(insights, func(insight types.InsightSummary) console.UpgradeInsightAttributes {
return algorithms.Map(insights, func(insight *types.Insight) console.UpgradeInsightAttributes {
var refreshedAt *string
if insight.LastRefreshTime != nil {
refreshedAt = lo.ToPtr(insight.LastRefreshTime.Format(time.RFC3339))
Expand All @@ -55,17 +56,19 @@ func (in *EKSCloudProvider) UpgradeInsights(ctx context.Context, ui v1alpha1.Upg
Version: insight.KubernetesVersion,
Description: insight.Description,
Status: in.fromInsightStatus(insight.InsightStatus),
Details: in.toInsightDetails(insight),
RefreshedAt: refreshedAt,
TransitionedAt: transitionedAt,
}
}), nil
}

func (in *EKSCloudProvider) listInsights(ctx context.Context, client *eks.Client, ui v1alpha1.UpgradeInsights) ([]types.InsightSummary, error) {
func (in *EKSCloudProvider) listInsights(ctx context.Context, client *eks.Client, ui v1alpha1.UpgradeInsights) ([]*types.Insight, error) {
logger := log.FromContext(ctx)
var result []types.InsightSummary

out, err := client.ListInsights(ctx, &eks.ListInsightsInput{
ClusterName: lo.ToPtr(ui.Spec.GetClusterName(in.clusterName)),
ClusterName: lo.ToPtr(in.clusterName),
})
if err != nil {
return nil, err
Expand All @@ -75,7 +78,7 @@ func (in *EKSCloudProvider) listInsights(ctx context.Context, client *eks.Client
nextToken := out.NextToken
for out.NextToken != nil {
out, err = client.ListInsights(ctx, &eks.ListInsightsInput{
ClusterName: lo.ToPtr(ui.Spec.GetClusterName(in.clusterName)),
ClusterName: lo.ToPtr(in.clusterName),
NextToken: nextToken,
})
if err != nil {
Expand All @@ -85,7 +88,23 @@ func (in *EKSCloudProvider) listInsights(ctx context.Context, client *eks.Client
nextToken = out.NextToken
}

return result, nil
return algorithms.Filter(
algorithms.Map(result, func(insight types.InsightSummary) *types.Insight {
output, err := client.DescribeInsight(ctx, &eks.DescribeInsightInput{
ClusterName: lo.ToPtr(in.clusterName),
Id: insight.Id,
})
// If there is an error getting the details of an insight just ignore.
// It will be picked up during the next reconcile.
if err != nil {
logger.Error(err, "could not describe insight", "clusterName", in.clusterName, "id", insight.Id)
return nil
}

return output.Insight
}), func(insight *types.Insight) bool {
return insight != nil
}), nil
}

func (in *EKSCloudProvider) fromInsightStatus(status *types.InsightStatus) *console.UpgradeInsightStatus {
Expand All @@ -106,6 +125,24 @@ func (in *EKSCloudProvider) fromInsightStatus(status *types.InsightStatus) *cons
return nil
}

func (in *EKSCloudProvider) toInsightDetails(insight *types.Insight) []*console.UpgradeInsightDetailAttributes {
if insight.CategorySpecificSummary == nil {
return nil
}

result := make([]*console.UpgradeInsightDetailAttributes, 0)
for _, r := range insight.CategorySpecificSummary.DeprecationDetails {
result = append(result, &console.UpgradeInsightDetailAttributes{
Used: r.Usage,
Replacement: r.ReplacedWith,
ReplacedIn: r.StartServingReplacementVersion,
RemovedIn: r.StopServingVersion,
})
}

return result
}

func (in *EKSCloudProvider) config(ctx context.Context, ui v1alpha1.UpgradeInsights) (aws.Config, error) {
// If credentials are not provided in the request, then use default credentials.
if ui.Spec.Credentials == nil || ui.Spec.Credentials.AWS == nil {
Expand Down
6 changes: 5 additions & 1 deletion internal/controller/upgradeinsights_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,11 @@ func (in *UpgradeInsightsController) handleDelete(ctx context.Context, ui *v1alp
}

func (in *UpgradeInsightsController) sync(ctx context.Context, ui *v1alpha1.UpgradeInsights) error {
cloudProvider, err := NewCloudProvider(ui.Spec.GetDistro(in.myCluster.GetDistro()), in.Client, in.myCluster.GetName())
cloudProvider, err := NewCloudProvider(
ui.Spec.GetDistro(in.myCluster.GetDistro()),
in.Client,
ui.Spec.GetClusterName(in.myCluster.GetName()),
)
if err != nil {
return err
}
Expand Down

0 comments on commit b39308f

Please sign in to comment.