Skip to content

Commit

Permalink
hack/generate-lib-resources.py: Add OperatorGroup type
Browse files Browse the repository at this point in the history
Add OperatorGroup type to the helper script generate-lib-resources.py.

This should have been a part of pull request #862, which introduced
the defaulting for OperatorGroup resources [1]. Unfortunately, it wasn't
added, and the respective changes in the auto-generated files
lib/resourcebuilder/resourcebuilder.go and
lib/resourceread/resourceread.go were done manually.

This commit will update the script and will update the auto-generated
files by running the helper script.

[1] #862
  • Loading branch information
DavidHurta committed Jan 31, 2023
1 parent 392a8ea commit bdac5ff
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 19 deletions.
2 changes: 2 additions & 0 deletions hack/generate-lib-resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ def scheme_group_versions(types):
types = {
'github.com/openshift/api/image/v1': {'ImageStream'}, # for payload loading
'github.com/openshift/api/security/v1': {'SecurityContextConstraints'},
'github.com/operator-framework/api/pkg/operators/v1': {'OperatorGroup'},
'k8s.io/api/apps/v1': {'DaemonSet', 'Deployment'},
'k8s.io/api/batch/v1': {'Job'},
'k8s.io/api/core/v1': {'ConfigMap', 'Namespace', 'Service', 'ServiceAccount'},
Expand All @@ -292,6 +293,7 @@ def scheme_group_versions(types):
'github.com/openshift/api/security/v1': {'package': 'github.com/openshift/client-go/security/clientset/versioned/typed/security/v1', 'type': 'SecurityV1Client'},
'github.com/openshift/api/config/v1': {'package': 'github.com/openshift/client-go/config/clientset/versioned/typed/config/v1', 'type': 'ConfigV1Client'},
'github.com/openshift/api/image/v1': {'package': 'github.com/openshift/client-go/image/clientset/versioned/typed/image/v1', 'type': 'ImageV1Client'},
'github.com/operator-framework/api/pkg/operators/v1': {'package': 'github.com/operator-framework/operator-lifecycle-manager/pkg/api/client/clientset/versioned/typed/operators/v1', 'type': 'OperatorsV1Client'},
'k8s.io/api/apps/v1': {'package': 'k8s.io/client-go/kubernetes/typed/apps/v1', 'type': 'AppsV1Client'},
'k8s.io/api/batch/v1': {'package': 'k8s.io/client-go/kubernetes/typed/batch/v1', 'type': 'BatchV1Client'},
'k8s.io/api/core/v1': {'package': 'k8s.io/client-go/kubernetes/typed/core/v1', 'type': 'CoreV1Client'},
Expand Down
30 changes: 15 additions & 15 deletions lib/resourcebuilder/resourcebuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ type builder struct {
configClientv1 *configclientv1.ConfigV1Client
coreClientv1 *coreclientv1.CoreV1Client
imageClientv1 *imageclientv1.ImageV1Client
operatorsClientv1 *operatorsclientv1.OperatorsV1Client
rbacClientv1 *rbacclientv1.RbacV1Client
securityClientv1 *securityclientv1.SecurityV1Client
operatorsClientv1 *operatorsclientv1.OperatorsV1Client
}

func newBuilder(config *rest.Config, m manifest.Manifest) Interface {
Expand All @@ -61,9 +61,9 @@ func newBuilder(config *rest.Config, m manifest.Manifest) Interface {
configClientv1: configclientv1.NewForConfigOrDie(config),
coreClientv1: coreclientv1.NewForConfigOrDie(withProtobuf(config)),
imageClientv1: imageclientv1.NewForConfigOrDie(config),
operatorsClientv1: operatorsclientv1.NewForConfigOrDie(config),
rbacClientv1: rbacclientv1.NewForConfigOrDie(withProtobuf(config)),
securityClientv1: securityclientv1.NewForConfigOrDie(config),
operatorsClientv1: operatorsclientv1.NewForConfigOrDie(config),
}
}

Expand Down Expand Up @@ -107,6 +107,18 @@ func (b *builder) Do(ctx context.Context) error {
return err
}
}
case *operatorsv1.OperatorGroup:
if b.modifier != nil {
b.modifier(typedObject)
}
if deleteReq, err := resourcedelete.DeleteOperatorGroupv1(ctx, b.operatorsClientv1, typedObject,
updatingMode); err != nil {
return err
} else if !deleteReq {
if _, _, err := resourceapply.ApplyOperatorGroupv1(ctx, b.operatorsClientv1, typedObject, reconcilingMode); err != nil {
return err
}
}
case *appsv1.DaemonSet:
if b.modifier != nil {
b.modifier(typedObject)
Expand Down Expand Up @@ -265,18 +277,6 @@ func (b *builder) Do(ctx context.Context) error {
return b.checkCustomResourceDefinitionHealth(ctx, actual)
}
}
case *operatorsv1.OperatorGroup:
if b.modifier != nil {
b.modifier(typedObject)
}
if deleteReq, err := resourcedelete.DeleteOperatorGroupv1(ctx, b.operatorsClientv1, typedObject,
updatingMode); err != nil {
return err
} else if !deleteReq {
if _, _, err := resourceapply.ApplyOperatorGroupv1(ctx, b.operatorsClientv1, typedObject, reconcilingMode); err != nil {
return err
}
}
default:
return fmt.Errorf("unrecognized manifest type: %T", obj)
}
Expand All @@ -295,11 +295,11 @@ func init() {
rm.RegisterGVK(corev1.SchemeGroupVersion.WithKind("Service"), newBuilder)
rm.RegisterGVK(corev1.SchemeGroupVersion.WithKind("ServiceAccount"), newBuilder)
rm.RegisterGVK(imagev1.SchemeGroupVersion.WithKind("ImageStream"), newBuilder)
rm.RegisterGVK(operatorsv1.SchemeGroupVersion.WithKind("OperatorGroup"), newBuilder)
rm.RegisterGVK(rbacv1.SchemeGroupVersion.WithKind("ClusterRole"), newBuilder)
rm.RegisterGVK(rbacv1.SchemeGroupVersion.WithKind("ClusterRoleBinding"), newBuilder)
rm.RegisterGVK(rbacv1.SchemeGroupVersion.WithKind("Role"), newBuilder)
rm.RegisterGVK(rbacv1.SchemeGroupVersion.WithKind("RoleBinding"), newBuilder)
rm.RegisterGVK(securityv1.SchemeGroupVersion.WithKind("SecurityContextConstraints"), newBuilder)
rm.RegisterGVK(operatorsv1.SchemeGroupVersion.WithKind("OperatorGroup"), newBuilder)
rm.AddToMap(Mapper)
}
8 changes: 4 additions & 4 deletions lib/resourceread/resourceread.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ func init() {
if err := imagev1.AddToScheme(scheme); err != nil {
panic(err)
}
if err := rbacv1.AddToScheme(scheme); err != nil {
if err := operatorsv1.AddToScheme(scheme); err != nil {
panic(err)
}
if err := securityv1.AddToScheme(scheme); err != nil {
if err := rbacv1.AddToScheme(scheme); err != nil {
panic(err)
}
if err := operatorsv1.AddToScheme(scheme); err != nil {
if err := securityv1.AddToScheme(scheme); err != nil {
panic(err)
}
decoder = codecs.UniversalDecoder(
Expand All @@ -53,9 +53,9 @@ func init() {
batchv1.SchemeGroupVersion,
corev1.SchemeGroupVersion,
imagev1.SchemeGroupVersion,
operatorsv1.SchemeGroupVersion,
rbacv1.SchemeGroupVersion,
securityv1.SchemeGroupVersion,
operatorsv1.SchemeGroupVersion,
)
}

Expand Down

0 comments on commit bdac5ff

Please sign in to comment.