Skip to content
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
21 changes: 8 additions & 13 deletions cmd/server/internal/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"encoding/json"
"errors"
"fmt"
"maps"
"net/http"
"net/url"
"strings"
Expand Down Expand Up @@ -434,9 +435,9 @@ func (s *SubscriptionHandler) getTenantByLabels(labelsMap map[string]string, nam
return &Result{Tenant: &ctList.Items[0], Message: ResourceFound}
}

func flattenLabels(labelsMap map[string]string, args ...interface{}) []interface{} {
func flattenLabels(labelsMap map[string]string, args ...any) []any {
// Converts the label map to a flat key-value slice for logging
var result []interface{}
var result []any
for k, v := range labelsMap {
result = append(result, k, v)
}
Expand Down Expand Up @@ -664,9 +665,7 @@ func (s *SubscriptionHandler) enrichAdditionalOutput(namespace string, tenantId
return err
}
// merge tenant data output into additional output
for k, v := range *tenantDataOutput {
(*additionalOutput)[k] = v
}
maps.Copy((*additionalOutput), *tenantDataOutput)
}
return nil
}
Expand Down Expand Up @@ -716,16 +715,12 @@ func (s *SubscriptionHandler) getServiceDetails(ca *v1alpha1.CAPApplication, ste
saasData *util.SaasRegistryCredentials
uaaData *util.XSUAACredentials
)
wg.Add(1)
go func() {
defer wg.Done()
wg.Go(func() {
saasData = s.getSaasDetails(ca, step)
}()
wg.Add(1)
go func() {
defer wg.Done()
})
wg.Go(func() {
uaaData = s.getXSUAADetails(ca, step)
}()
})

wg.Wait()
return saasData, uaaData
Expand Down
6 changes: 3 additions & 3 deletions cmd/server/internal/jwt.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func getOpenIDConfig(uaaURL string, client *http.Client) (*OpenIDConfig, error)

// token validation for XSUAA token implemented by following the guidelines provided -> CPSecurity/Knowledge-Base/03_ApplicationSecurity/TokenValidation/
func VerifyXSUAAJWTToken(ctx context.Context, tokenString string, config *XSUAAConfig, client *http.Client) error {
_, err := jwt.ParseWithClaims(tokenString, &XSUAAJWTClaims{}, func(t *jwt.Token) (interface{}, error) {
_, err := jwt.ParseWithClaims(tokenString, &XSUAAJWTClaims{}, func(t *jwt.Token) (any, error) {
// verify claims excluding expiration (as this is now done internally in jwt v5)
err := verifyClaims(t, config)
if err != nil {
Expand Down Expand Up @@ -204,8 +204,8 @@ func appendWithTrim(s []string, v string) []string {
func adjustForNamespace(s []string, ignoreIfNotNamespaced bool) []string {
r := []string{}
for _, v := range s {
if i := strings.Index(v, "."); i > -1 {
r = appendWithTrim(r, v[:i])
if before, _, ok := strings.Cut(v, "."); ok {
r = appendWithTrim(r, before)
} else if !ignoreIfNotNamespaced { // when processing scope, add to list only when namespaced
r = appendWithTrim(r, v)
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/server/internal/jwt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ func testInvalidClaimsType(t *testing.T) {

_, tokenString, _ := setupTokenAndIssuer(testXSUAAConfig, &jwtTestParameters{})

token, _ := jwt.ParseWithClaims(tokenString, &foo{}, func(t *jwt.Token) (interface{}, error) {
token, _ := jwt.ParseWithClaims(tokenString, &foo{}, func(t *jwt.Token) (any, error) {
return []byte("Test"), nil
})

Expand Down
2 changes: 1 addition & 1 deletion cmd/web-hooks/internal/handler/mutate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func newTestHandler(objects ...runtime.Object) *WebhookHandler {
}
}

func marshalJSON(obj interface{}) []byte {
func marshalJSON(obj any) []byte {
b, err := json.Marshal(obj)
if err != nil {
panic(err)
Expand Down
4 changes: 2 additions & 2 deletions internal/controller/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -491,8 +491,8 @@ func readYAMLResourcesFromFile(file string) ([][]byte, error) {

resources := [][]byte{}
fileContents := string(i)
splits := strings.Split(fileContents, "---")
for _, part := range splits {
splits := strings.SplitSeq(fileContents, "---")
for part := range splits {
if part == "\n" || part == "" {
continue
}
Expand Down
6 changes: 2 additions & 4 deletions internal/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,11 +191,9 @@ func (c *Controller) Start(ctx context.Context) {
}

// start version cleanup routines
wg.Add(1)
go func() {
defer wg.Done()
wg.Go(func() {
c.startVersionCleanup(qCxt)
}()
})

// wait for workers
wg.Wait()
Expand Down
2 changes: 1 addition & 1 deletion internal/controller/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ type dummyInformerFactoryType struct {

func (f *dummyInformerFactoryType) WaitForCacheSync(_ <-chan struct{}) map[reflect.Type]bool {
//Simulate error
return map[reflect.Type]bool{reflect.TypeOf(metav1.TypeMeta{}): false}
return map[reflect.Type]bool{reflect.TypeFor[metav1.TypeMeta](): false}
}

func (f *dummyInformerFactoryType) Batch() batch.Interface {
Expand Down
10 changes: 5 additions & 5 deletions internal/controller/informers.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,13 @@ func (c *Controller) initializeInformers() {

func (c *Controller) getEventHandlerFuncsForResource(res int) cache.ResourceEventHandlerFuncs {
return cache.ResourceEventHandlerFuncs{
AddFunc: func(new interface{}) {
AddFunc: func(new any) {
c.enqueueModifiedResource(res, new, nil)
},
UpdateFunc: func(old, new interface{}) {
UpdateFunc: func(old, new any) {
c.enqueueModifiedResource(res, new, old)
},
DeleteFunc: func(old interface{}) {
DeleteFunc: func(old any) {
c.enqueueModifiedResource(res, old, nil)
},
}
Expand Down Expand Up @@ -185,7 +185,7 @@ func (c *Controller) registerGardenerDNSEntrytListeners() {
AddEventHandler(c.getEventHandlerFuncsForResource(ResourceDNSEntry))
}

func (c *Controller) enqueueModifiedResource(sourceKey int, new, old interface{}) {
func (c *Controller) enqueueModifiedResource(sourceKey int, new, old any) {
newObj, ok := getMetaObject(new)
if !ok {
return
Expand Down Expand Up @@ -222,7 +222,7 @@ func (c *Controller) enqueueModifiedResource(sourceKey int, new, old interface{}
}
}

func getMetaObject(obj interface{}) (metav1.Object, bool) {
func getMetaObject(obj any) (metav1.Object, bool) {
if obj == nil {
return nil, false
}
Expand Down
2 changes: 1 addition & 1 deletion internal/controller/informers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func TestController_initializeInformers(t *testing.T) {
}

testC.initializeInformers()
var res interface{}
var res any
switch tt.res {
case ResourceCAPApplication:
res = createCaCRO(tt.itemName, false)
Expand Down
9 changes: 3 additions & 6 deletions internal/controller/reconcile.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"context"
"encoding/json"
"fmt"
"maps"
"slices"
"strings"

Expand Down Expand Up @@ -617,12 +618,8 @@ func (c *Controller) getRouterServicePortInfo(cavName, namespace string) (*servi

func copyMaps(originalMap, additionalMap map[string]string) map[string]string {
newMap := map[string]string{}
for key, value := range originalMap {
newMap[key] = value
}
for key, value := range additionalMap {
newMap[key] = value
}
maps.Copy(newMap, originalMap)
maps.Copy(newMap, additionalMap)
return newMap
}

Expand Down
2 changes: 1 addition & 1 deletion internal/controller/reconcile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ func generateName(namePrefix string) string {
return namePrefix + rand.String(5)
}

func generateMetaObjName(obj interface{}) {
func generateMetaObjName(obj any) {
metaObj, _ := meta.Accessor(obj)
if metaObj.GetName() == "" && metaObj.GetGenerateName() != "" {
metaObj.SetName(generateName(metaObj.GetGenerateName()))
Expand Down
2 changes: 1 addition & 1 deletion internal/controller/version-monitoring.go
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ func evaluateMetric(ctx context.Context, rule *v1alpha1.MetricRule, job, ns stri
if len(vec) > 0 {
sample := vec[0] // use the first one - expecting only one sample based on the expressions
var threshold prommodel.SampleValue
err = threshold.UnmarshalJSON([]byte(fmt.Sprintf("\"%s\"", rule.ThresholdValue)))
err = threshold.UnmarshalJSON(fmt.Appendf(nil, "\"%s\"", rule.ThresholdValue))
if err != nil {
klog.ErrorS(err, "error parsing threshold value", "value", rule.ThresholdValue, "metric", rule.Name)
return false, err
Expand Down
6 changes: 2 additions & 4 deletions internal/controller/version-monitoring_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,9 @@ func TestGracefulShutdownMonitoringRoutines(t *testing.T) {

var wg sync.WaitGroup

wg.Add(1)
go func() {
wg.Go(func() {
c.startVersionCleanup(testCtx)
wg.Done()
}()
})

wg.Wait() // check whether routines are closing - or test timeout
}
Expand Down
16 changes: 8 additions & 8 deletions internal/util/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func GetLogger() logr.Logger {
return zapr.NewLogger(logger)
}

func extractEntityMeta(entity interface{}, isRoot bool, skipLabel bool) map[string]string {
func extractEntityMeta(entity any, isRoot bool, skipLabel bool) map[string]string {
obj, _ := runtime.DefaultUnstructuredConverter.ToUnstructured(entity)
objectMeta := &unstructured.Unstructured{Object: obj}
// Try to get the kind from the object meta
Expand Down Expand Up @@ -70,16 +70,16 @@ func extractEntityMeta(entity interface{}, isRoot bool, skipLabel bool) map[stri
return args
}

func extractArgs(entityMeta map[string]string) []interface{} {
args := []interface{}{}
func extractArgs(entityMeta map[string]string) []any {
args := []any{}
for key, val := range entityMeta {
args = append(args, key, val)
}
return args
}

func logArgs(step string, entity interface{}, child interface{}, inArgs ...interface{}) []interface{} {
args := []interface{}{}
func logArgs(step string, entity any, child any, inArgs ...any) []any {
args := []any{}
skipLabel := false
args = append(args, Step, step)

Expand All @@ -103,16 +103,16 @@ func logArgs(step string, entity interface{}, child interface{}, inArgs ...inter
return args
}

func LogInfo(msg string, step string, entity interface{}, child interface{}, args ...interface{}) {
func LogInfo(msg string, step string, entity any, child any, args ...any) {
overallArgs := logArgs(step, entity, child, args...)
klog.InfoS(msg, overallArgs...)
}

func LogError(error error, msg string, step string, entity interface{}, child interface{}, args ...interface{}) {
func LogError(error error, msg string, step string, entity any, child any, args ...any) {
overallArgs := logArgs(step, entity, child, args...)
klog.ErrorS(error, msg, overallArgs...)
}

func LogWarning(args ...interface{}) {
func LogWarning(args ...any) {
klog.Warning(args...)
}
14 changes: 7 additions & 7 deletions internal/util/log_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,20 @@ func TestLogging(t *testing.T) {
err error
msg string
step string
entity interface{}
child interface{}
args []interface{}
entity any
child any
args []any
}
tests := []struct {
name string
error bool
warn bool
args args
}{
{name: "Test LogInfo", error: false, args: args{msg: "LogInfo basic test", step: "LogInfoStep0", entity: "LogInfo", child: "ChildLogInfo", args: []interface{}{"LogInfo", "No missing value"}}},
{name: "Test LogInfo", error: false, args: args{msg: "LogInfo pointer test", step: "LogInfoStep0", entity: "LogInfo", child: jobType, args: []interface{}{"LogInfo", "No missing value"}}},
{name: "Test LogError", error: true, args: args{err: errors.New("Test Error"), msg: "LogError basic test", step: "LogErrorStep0", entity: "LogError", child: "ChildLogError", args: []interface{}{"LogError", "No Missing value"}}},
{name: "Test LogError", error: true, args: args{err: errors.New("Test Error"), msg: "LogError LabelBTPApplicationIdentifierHash skip test", step: "LogErrorStep0", entity: "LogError", child: jobType, args: []interface{}{LabelBTPApplicationIdentifierHash, "some-test-hash", "Missing value"}}},
{name: "Test LogInfo", error: false, args: args{msg: "LogInfo basic test", step: "LogInfoStep0", entity: "LogInfo", child: "ChildLogInfo", args: []any{"LogInfo", "No missing value"}}},
{name: "Test LogInfo", error: false, args: args{msg: "LogInfo pointer test", step: "LogInfoStep0", entity: "LogInfo", child: jobType, args: []any{"LogInfo", "No missing value"}}},
{name: "Test LogError", error: true, args: args{err: errors.New("Test Error"), msg: "LogError basic test", step: "LogErrorStep0", entity: "LogError", child: "ChildLogError", args: []any{"LogError", "No Missing value"}}},
{name: "Test LogError", error: true, args: args{err: errors.New("Test Error"), msg: "LogError LabelBTPApplicationIdentifierHash skip test", step: "LogErrorStep0", entity: "LogError", child: jobType, args: []any{LabelBTPApplicationIdentifierHash, "some-test-hash", "Missing value"}}},
{name: "Test LogWarn", warn: true, args: args{err: errors.New("Test Warn"), msg: "LogWarn LabelBTPApplicationIdentifierHash skip test"}},
}
for _, tt := range tests {
Expand Down
18 changes: 9 additions & 9 deletions internal/util/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ SPDX-License-Identifier: Apache-2.0
package util

type VCAPServiceInstance struct {
Name string `json:"name"` // this attribute holds the binding name if it exists, otherwise, instance name
BindingGUID string `json:"binding_guid,omitempty"`
BindingName string `json:"binding_name,omitempty"`
InstanceGUID string `json:"instance_guid,omitempty"`
InstanceName string `json:"instance_name,omitempty"`
Label string `json:"label"`
Plan string `json:"plan,omitempty"`
Credentials interface{} `json:"credentials"`
Tags []string `json:"tags,omitempty"`
Name string `json:"name"` // this attribute holds the binding name if it exists, otherwise, instance name
BindingGUID string `json:"binding_guid,omitempty"`
BindingName string `json:"binding_name,omitempty"`
InstanceGUID string `json:"instance_guid,omitempty"`
InstanceName string `json:"instance_name,omitempty"`
Label string `json:"label"`
Plan string `json:"plan,omitempty"`
Credentials any `json:"credentials"`
Tags []string `json:"tags,omitempty"`
}

type CredentialData struct {
Expand Down