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

Enhance Restarts for Fix Packs #187

Open
wants to merge 24 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
6cb9a2d
Add missing k8s_builder config to v25 core.yaml (#184)
jt-nti Apr 2, 2024
446ea7b
Address CVE-2024-24786 in google.golang.org/protobuf. (#186)
benjsmi Apr 4, 2024
2c67e3c
Adding logs with uber/zap (#185)
shoaebjindani Apr 8, 2024
0906416
Adding logic to check fixpacks
Apr 9, 2024
1e4a162
removed unnecessary method
Apr 9, 2024
3dd4291
Do not use Mustgather here
Apr 19, 2024
76840e6
Updated the logic comment
Apr 19, 2024
4567cea
Updated the comments about logic
Apr 19, 2024
c9b62ae
Move to golang.org/x/net v0.24.0 for CVE-2023-45288. (#191)
benjsmi Apr 17, 2024
a2fc85d
Upgrade github.com/docker/docker to v25.0.5 to address CVE-2024-29018…
benjsmi Apr 26, 2024
e1c2176
Fixed HSM Library Upgrade Path for 2.5.x Scenario (#195)
shoaebjindani May 28, 2024
d8014b2
update latest version in deployer config map template (#193)
MuthuSundaravadivel May 31, 2024
4a42c08
Bump Go to 1.21.11 (#197)
denyeart Jul 18, 2024
e724c8a
Use ubi-minimal image instead of ubi go-toolset (#198)
denyeart Jul 18, 2024
d1d365f
Bump Go to 1.22.5 (#199)
denyeart Jul 23, 2024
0170c61
Bump fabric, fabric-ca, fabric-lib-go (#200)
denyeart Jul 23, 2024
22d57c5
fix for CVE-2024-41110 (#203)
ketulsha Aug 19, 2024
c622da6
Fix gosec failures on integer conversion (#206)
denyeart Sep 11, 2024
6a44f97
Bump github.com/DataDog/zstd to v1.5.6 (#205)
denyeart Sep 12, 2024
60230ab
Updating maintainers list to add and remove maintainers (#207)
shoaebjindani Sep 12, 2024
7c4cb82
Bump go to 1.23.1
Sep 17, 2024
e4cda26
Merge branch 'main' into FixPacksEnhancement_1
shoaebjindani Sep 20, 2024
1f6c54b
Supress G104
Sep 20, 2024
cad433f
Merge branch 'FixPacksEnhancement_1' of https://github.com/shoaebjind…
Sep 20, 2024
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
90 changes: 89 additions & 1 deletion pkg/command/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,22 @@ import (
"fmt"
"os"
"runtime"
"strings"
"time"

"go.uber.org/zap/zapcore"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
k8sruntime "k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"

"github.com/go-logr/zapr"
routev1 "github.com/openshift/api/route/v1"
"github.com/operator-framework/operator-lib/leader"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
"k8s.io/client-go/dynamic"
"k8s.io/client-go/kubernetes"
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
"k8s.io/client-go/rest"
ctrl "sigs.k8s.io/controller-runtime"

"github.com/pkg/errors"
Expand All @@ -42,16 +48,19 @@ import (
apis "github.com/IBM-Blockchain/fabric-operator/api"
ibpv1beta1 "github.com/IBM-Blockchain/fabric-operator/api/v1beta1"
controller "github.com/IBM-Blockchain/fabric-operator/controllers"
"github.com/IBM-Blockchain/fabric-operator/defaultconfig/console"
oconfig "github.com/IBM-Blockchain/fabric-operator/operatorconfig"
"github.com/IBM-Blockchain/fabric-operator/pkg/migrator"
"github.com/IBM-Blockchain/fabric-operator/pkg/offering"
"github.com/IBM-Blockchain/fabric-operator/pkg/util"
openshiftv1 "github.com/openshift/api/config/v1"

"k8s.io/apimachinery/pkg/types"
_ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
"sigs.k8s.io/controller-runtime/pkg/client"

uberzap "go.uber.org/zap"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
logf "sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/manager/signals"
)
Expand Down Expand Up @@ -169,7 +178,7 @@ func OperatorWithSignal(operatorCfg *oconfig.Config, signalHandler context.Conte
"Enabling this will ensure there is only one active controller manager.")
}
flag.Parse()

config := ctrl.GetConfigOrDie()
mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
Scheme: scheme,
MetricsBindAddress: metricsAddr,
Expand All @@ -186,6 +195,10 @@ func OperatorWithSignal(operatorCfg *oconfig.Config, signalHandler context.Conte

log.Info("Registering Components.")

//This Method Checks if Console deployment Tag in Console Deployment is same as the console tag in the operator
// binary (if it is not same, it delete the configmaps $consoleObject-deployer and $consoleObject-console)
CheckForFixPacks(config, operatorNamespace)

// Setup Scheme for all resources
if err := apis.AddToScheme(mgr.GetScheme()); err != nil {
log.Error(err, "")
Expand Down Expand Up @@ -312,3 +325,78 @@ func GetOperatorNamespace() (string, error) {

return operatorNamespace, nil
}
func CheckForFixPacks(config *rest.Config, operatornamespace string) {
clientset, err := kubernetes.NewForConfig(config)

// Create a dynamic client
dynamicClient := dynamic.NewForConfigOrDie(config)

// Define your custom resource type
//customResourceName := "ibpconsoles"
//customResourceNamespace := "ibmsupport"
gvr := schema.GroupVersionResource{
Group: "ibp.com",
Version: "v1beta1",
Resource: "ibpconsoles",
}

// Retrieve the list of objects in your custom resource
list, err := dynamicClient.Resource(gvr).Namespace(operatornamespace).List(context.Background(), metav1.ListOptions{})
if err != nil {
panic(err.Error())
}

var consoleObjectName string
// Print the names of all objects
for _, obj := range list.Items {

consoleObjectName = obj.GetName()
// If you want to do something with the object, you can access it here

}
log.Info(fmt.Sprintf("Latest Console Tag is %s", console.GetImages().ConsoleTag))

// get the console deployment here

// Retrieve the deployment
deployment, err := clientset.AppsV1().Deployments(operatornamespace).Get(context.TODO(), consoleObjectName, v1.GetOptions{})
if err != nil {
panic(err.Error())
}
existingConsoleDeploymentImageTag := strings.Split(deployment.Spec.Template.Spec.Containers[0].Image, ":")[1]

log.Info(fmt.Sprintf("Operator Binary Console Tag is %s and current Console Deployment tag is %s", console.GetImages().ConsoleTag, existingConsoleDeploymentImageTag))

//if the latest console deployment tag and operator binary latest console tag are not same, then we will delete the below two configmaps
if console.GetImages().ConsoleTag != existingConsoleDeploymentImageTag {
log.Info(fmt.Sprintf("Will Start Applying the Fixpacks Existing Version %s to New Version %s ", existingConsoleDeploymentImageTag, console.GetImages().ConsoleTag))

// set the webhook image here as well
// Specify deployment namespace and name
namespace := "ibm-hlfsupport-infra"
deploymentName := "ibm-hlfsupport-webhook"

// Retrieve the deployment
deployment, err := clientset.AppsV1().Deployments(namespace).Get(context.TODO(), deploymentName, v1.GetOptions{})
if err != nil {
panic(err.Error())
}
existingwebhookimage := strings.Split(deployment.Spec.Template.Spec.Containers[0].Image, ":")[0]
existingwebhookimage = existingwebhookimage + ":" + console.GetImages().ConsoleTag

deployment.Spec.Template.Spec.Containers[0].Image = existingwebhookimage

// Update the deployment
_, err = clientset.AppsV1().Deployments(namespace).Update(context.TODO(), deployment, v1.UpdateOptions{})
if err != nil {
panic(err.Error())
}

util.DeleteConfigMapIfExists(clientset, operatornamespace, consoleObjectName+"-console") // #nosec G104
util.DeleteConfigMapIfExists(clientset, operatornamespace, consoleObjectName+"-deployer") // #nosec G104

} else {
log.Info("Looks like the operator was restarted...")
}

}
22 changes: 22 additions & 0 deletions pkg/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import (
"go.uber.org/zap/zapcore"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
v1 "k8s.io/api/core/v1"
networkingv1 "k8s.io/api/networking/v1"
networkingv1beta1 "k8s.io/api/networking/v1beta1"
rbacv1 "k8s.io/api/rbac/v1"
Expand All @@ -54,6 +55,7 @@ import (
"k8s.io/apimachinery/pkg/util/strategicpatch"
"k8s.io/apimachinery/pkg/util/yaml"
"k8s.io/apimachinery/pkg/version"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
k8sclient "sigs.k8s.io/controller-runtime/pkg/client"
yaml1 "sigs.k8s.io/yaml"
Expand Down Expand Up @@ -965,3 +967,23 @@ func SetupLogging(loglevel string) (*uberzap.Logger, error) {

return logger, nil
}
func GetConfigMap(clientset *kubernetes.Clientset, namespace, configMapName string) (*v1.ConfigMap, error) {
configMap, err := clientset.CoreV1().ConfigMaps(namespace).Get(context.TODO(), configMapName, metav1.GetOptions{})
if err != nil {
return nil, err
}
return configMap, nil
}
func DeleteConfigMapIfExists(clientset *kubernetes.Clientset, namespace, configMapName string) error {
_, err := clientset.CoreV1().ConfigMaps(namespace).Get(context.TODO(), configMapName, metav1.GetOptions{})
if err != nil {
return nil
}

err = clientset.CoreV1().ConfigMaps(namespace).Delete(context.TODO(), configMapName, metav1.DeleteOptions{})
if err != nil {
return err
}
return nil
}

Loading