/
samples.go
84 lines (73 loc) · 2.08 KB
/
samples.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package cluster
// Copyright (c) Microsoft Corporation.
// Licensed under the Apache License 2.0.
import (
"context"
configv1 "github.com/openshift/api/config/v1"
operatorv1 "github.com/openshift/api/operator/v1"
configscheme "github.com/openshift/client-go/config/clientset/versioned/scheme"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/util/retry"
)
// disableSamples disables the samples if there's no appropriate pull secret
func (i *manager) disableSamples(ctx context.Context) error {
if !i.env.IsDevelopment() &&
i.doc.OpenShiftCluster.Properties.ClusterProfile.PullSecret != "" {
return nil
}
return retry.RetryOnConflict(retry.DefaultRetry, func() error {
c, err := i.samplescli.SamplesV1().Configs().Get("cluster", metav1.GetOptions{})
if err != nil {
return err
}
c.Spec.ManagementState = operatorv1.Removed
_, err = i.samplescli.SamplesV1().Configs().Update(c)
return err
})
}
// disableOperatorHubSources disables operator hub sources if there's no
// appropriate pull secret
func (i *manager) disableOperatorHubSources(ctx context.Context) error {
if !i.env.IsDevelopment() &&
i.doc.OpenShiftCluster.Properties.ClusterProfile.PullSecret != "" {
return nil
}
// https://bugzilla.redhat.com/show_bug.cgi?id=1815649
return retry.RetryOnConflict(retry.DefaultRetry, func() error {
c := &configv1.OperatorHub{}
err := i.configcli.ConfigV1().RESTClient().Get().
Resource("operatorhubs").
Name("cluster").
VersionedParams(&metav1.GetOptions{}, configscheme.ParameterCodec).
Do().
Into(c)
if err != nil {
return err
}
sources := []configv1.HubSource{
{
Name: "certified-operators",
Disabled: true,
},
{
Name: "redhat-operators",
Disabled: true,
},
}
for _, s := range c.Spec.Sources {
switch s.Name {
case "certified-operators", "redhat-operators":
default:
sources = append(sources, s)
}
}
c.Spec.Sources = sources
err = i.configcli.ConfigV1().RESTClient().Put().
Resource("operatorhubs").
Name("cluster").
Body(c).
Do().
Into(c)
return err
})
}